diff --git a/agents-api/agents_api/clients/temporal.py b/agents-api/agents_api/clients/temporal.py index 77e246286..ddc6d0571 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, @@ -33,18 +34,24 @@ 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 = {"temporal-namespace": namespace} return await Client.connect( worker_url, namespace=namespace, tls=tls_config, data_converter=data_converter, + api_key=temporal_api_key or None, + rpc_metadata=rpc_metadata, ) @@ -54,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 = {"temporal-namespace": namespace} new_runtime = Runtime( telemetry=TelemetryConfig( @@ -76,6 +87,8 @@ async def get_client_with_metrics( data_converter=data_converter, runtime=new_runtime, interceptors=[TracingInterceptor()], + api_key=temporal_api_key or None, + rpc_metadata=rpc_metadata, ) 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}