From 57b515ca6bb88dfb15c000770d7b46e5cf7424e1 Mon Sep 17 00:00:00 2001 From: Dmitry Paramonov Date: Wed, 8 Jan 2025 09:17:52 +0300 Subject: [PATCH 1/4] feat: Add temporal API key --- agents-api/agents_api/clients/temporal.py | 3 +++ agents-api/agents_api/env.py | 1 + agents-api/docker-compose.yml | 1 + 3 files changed, 5 insertions(+) diff --git a/agents-api/agents_api/clients/temporal.py b/agents-api/agents_api/clients/temporal.py index 77e246286..e4cb3f061 100644 --- a/agents-api/agents_api/clients/temporal.py +++ b/agents-api/agents_api/clients/temporal.py @@ -16,6 +16,7 @@ from ..common.protocol.tasks import ExecutionInput from ..common.retry_policies import DEFAULT_RETRY_POLICY from ..env import ( + temporal_api_key, temporal_client_cert, temporal_metrics_bind_host, temporal_metrics_bind_port, @@ -45,6 +46,7 @@ async def get_client( namespace=namespace, tls=tls_config, data_converter=data_converter, + api_key=temporal_api_key or None, ) @@ -76,6 +78,7 @@ async def get_client_with_metrics( data_converter=data_converter, runtime=new_runtime, interceptors=[TracingInterceptor()], + api_key=temporal_api_key or None, ) diff --git a/agents-api/agents_api/env.py b/agents-api/agents_api/env.py index a5b37aaae..f81547d87 100644 --- a/agents-api/agents_api/env.py +++ b/agents-api/agents_api/env.py @@ -99,6 +99,7 @@ temporal_namespace: str = env.str("TEMPORAL_NAMESPACE", default="default") temporal_client_cert: str = env.str("TEMPORAL_CLIENT_CERT", default=None) temporal_private_key: str = env.str("TEMPORAL_PRIVATE_KEY", default=None) +temporal_api_key: str = env.str("TEMPORAL_API_KEY", default=None) temporal_endpoint: Any = env.str("TEMPORAL_ENDPOINT", default="localhost:7233") temporal_task_queue: Any = env.str("TEMPORAL_TASK_QUEUE", default="julep-task-queue") temporal_schedule_to_close_timeout: int = env.int( diff --git a/agents-api/docker-compose.yml b/agents-api/docker-compose.yml index 2116eafbc..d5f144565 100644 --- a/agents-api/docker-compose.yml +++ b/agents-api/docker-compose.yml @@ -19,6 +19,7 @@ x--shared-environment: &shared-environment TEMPORAL_NAMESPACE: ${TEMPORAL_NAMESPACE:-default} TEMPORAL_TASK_QUEUE: ${TEMPORAL_TASK_QUEUE:-julep-task-queue} TEMPORAL_WORKER_URL: ${TEMPORAL_WORKER_URL:-temporal:7233} + TEMPORAL_API_KEY: ${TEMPORAL_API_KEY:-} TEMPORAL_SCHEDULE_TO_CLOSE_TIMEOUT: ${TEMPORAL_SCHEDULE_TO_CLOSE_TIMEOUT:-3600} TEMPORAL_METRICS_BIND_HOST: ${TEMPORAL_METRICS_BIND_HOST:-0.0.0.0} TEMPORAL_METRICS_BIND_PORT: ${TEMPORAL_METRICS_BIND_PORT:-14000} From 6bed999527b8ae24f4ae3d27e86336e7085203b9 Mon Sep 17 00:00:00 2001 From: Dmitry Paramonov Date: Wed, 8 Jan 2025 11:15:53 +0300 Subject: [PATCH 2/4] fix: Add more parameters to connect to temporal cloud --- agents-api/agents_api/clients/temporal.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/agents-api/agents_api/clients/temporal.py b/agents-api/agents_api/clients/temporal.py index e4cb3f061..aecd7f8e4 100644 --- a/agents-api/agents_api/clients/temporal.py +++ b/agents-api/agents_api/clients/temporal.py @@ -34,12 +34,16 @@ async def get_client( data_converter=pydantic_data_converter, ): tls_config = False + rpc_metadata = {} if temporal_private_key and temporal_client_cert: tls_config = TLSConfig( client_cert=temporal_client_cert.encode(), client_private_key=temporal_private_key.encode(), ) + elif temporal_api_key: + tls_config = True + rpc_metadata = rpc_metadata={"temporal-namespace": namespace} return await Client.connect( worker_url, @@ -47,6 +51,7 @@ async def get_client( tls=tls_config, data_converter=data_converter, api_key=temporal_api_key or None, + rpc_metadata=rpc_metadata, ) @@ -56,12 +61,16 @@ async def get_client_with_metrics( data_converter=pydantic_data_converter, ): tls_config = False + rpc_metadata = {} if temporal_private_key and temporal_client_cert: tls_config = TLSConfig( client_cert=temporal_client_cert.encode(), client_private_key=temporal_private_key.encode(), ) + elif temporal_api_key: + tls_config = True + rpc_metadata = rpc_metadata={"temporal-namespace": namespace} new_runtime = Runtime( telemetry=TelemetryConfig( @@ -79,6 +88,7 @@ async def get_client_with_metrics( runtime=new_runtime, interceptors=[TracingInterceptor()], api_key=temporal_api_key or None, + rpc_metadata=rpc_metadata, ) From a0f19f5348e8f5d27f23bdae7fdb42fa566e042d Mon Sep 17 00:00:00 2001 From: whiterabbit1983 Date: Wed, 8 Jan 2025 08:16:50 +0000 Subject: [PATCH 3/4] refactor: Lint agents-api (CI) --- agents-api/agents_api/clients/temporal.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/agents-api/agents_api/clients/temporal.py b/agents-api/agents_api/clients/temporal.py index aecd7f8e4..567128778 100644 --- a/agents-api/agents_api/clients/temporal.py +++ b/agents-api/agents_api/clients/temporal.py @@ -43,7 +43,7 @@ async def get_client( ) elif temporal_api_key: tls_config = True - rpc_metadata = rpc_metadata={"temporal-namespace": namespace} + rpc_metadata = rpc_metadata = {"temporal-namespace": namespace} return await Client.connect( worker_url, @@ -70,7 +70,7 @@ async def get_client_with_metrics( ) elif temporal_api_key: tls_config = True - rpc_metadata = rpc_metadata={"temporal-namespace": namespace} + rpc_metadata = rpc_metadata = {"temporal-namespace": namespace} new_runtime = Runtime( telemetry=TelemetryConfig( From 8029c009528f396156f8ace84d253b5eebead847 Mon Sep 17 00:00:00 2001 From: Dmitry Paramonov Date: Wed, 8 Jan 2025 11:23:02 +0300 Subject: [PATCH 4/4] fix: Remove extra var --- agents-api/agents_api/clients/temporal.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/agents-api/agents_api/clients/temporal.py b/agents-api/agents_api/clients/temporal.py index 567128778..ddc6d0571 100644 --- a/agents-api/agents_api/clients/temporal.py +++ b/agents-api/agents_api/clients/temporal.py @@ -43,7 +43,7 @@ async def get_client( ) elif temporal_api_key: tls_config = True - rpc_metadata = rpc_metadata = {"temporal-namespace": namespace} + rpc_metadata = {"temporal-namespace": namespace} return await Client.connect( worker_url, @@ -70,7 +70,7 @@ async def get_client_with_metrics( ) elif temporal_api_key: tls_config = True - rpc_metadata = rpc_metadata = {"temporal-namespace": namespace} + rpc_metadata = {"temporal-namespace": namespace} new_runtime = Runtime( telemetry=TelemetryConfig(