agentex-sdk 0.1.0a6__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- agentex/__init__.py +103 -0
- agentex/_base_client.py +1992 -0
- agentex/_client.py +506 -0
- agentex/_compat.py +219 -0
- agentex/_constants.py +14 -0
- agentex/_exceptions.py +108 -0
- agentex/_files.py +123 -0
- agentex/_models.py +829 -0
- agentex/_qs.py +150 -0
- agentex/_resource.py +43 -0
- agentex/_response.py +830 -0
- agentex/_streaming.py +333 -0
- agentex/_types.py +219 -0
- agentex/_utils/__init__.py +57 -0
- agentex/_utils/_logs.py +25 -0
- agentex/_utils/_proxy.py +65 -0
- agentex/_utils/_reflection.py +42 -0
- agentex/_utils/_resources_proxy.py +24 -0
- agentex/_utils/_streams.py +12 -0
- agentex/_utils/_sync.py +86 -0
- agentex/_utils/_transform.py +447 -0
- agentex/_utils/_typing.py +151 -0
- agentex/_utils/_utils.py +422 -0
- agentex/_version.py +4 -0
- agentex/lib/.keep +4 -0
- agentex/lib/__init__.py +0 -0
- agentex/lib/adk/__init__.py +41 -0
- agentex/lib/adk/_modules/__init__.py +0 -0
- agentex/lib/adk/_modules/acp.py +247 -0
- agentex/lib/adk/_modules/agent_task_tracker.py +176 -0
- agentex/lib/adk/_modules/agents.py +77 -0
- agentex/lib/adk/_modules/events.py +141 -0
- agentex/lib/adk/_modules/messages.py +285 -0
- agentex/lib/adk/_modules/state.py +291 -0
- agentex/lib/adk/_modules/streaming.py +75 -0
- agentex/lib/adk/_modules/tasks.py +124 -0
- agentex/lib/adk/_modules/tracing.py +194 -0
- agentex/lib/adk/providers/__init__.py +9 -0
- agentex/lib/adk/providers/_modules/__init__.py +0 -0
- agentex/lib/adk/providers/_modules/litellm.py +232 -0
- agentex/lib/adk/providers/_modules/openai.py +416 -0
- agentex/lib/adk/providers/_modules/sgp.py +85 -0
- agentex/lib/adk/utils/__init__.py +5 -0
- agentex/lib/adk/utils/_modules/__init__.py +0 -0
- agentex/lib/adk/utils/_modules/templating.py +94 -0
- agentex/lib/cli/__init__.py +0 -0
- agentex/lib/cli/commands/__init__.py +0 -0
- agentex/lib/cli/commands/agents.py +328 -0
- agentex/lib/cli/commands/init.py +227 -0
- agentex/lib/cli/commands/main.py +33 -0
- agentex/lib/cli/commands/secrets.py +169 -0
- agentex/lib/cli/commands/tasks.py +118 -0
- agentex/lib/cli/commands/uv.py +133 -0
- agentex/lib/cli/handlers/__init__.py +0 -0
- agentex/lib/cli/handlers/agent_handlers.py +160 -0
- agentex/lib/cli/handlers/cleanup_handlers.py +186 -0
- agentex/lib/cli/handlers/deploy_handlers.py +351 -0
- agentex/lib/cli/handlers/run_handlers.py +452 -0
- agentex/lib/cli/handlers/secret_handlers.py +670 -0
- agentex/lib/cli/templates/default/.dockerignore.j2 +43 -0
- agentex/lib/cli/templates/default/Dockerfile-uv.j2 +42 -0
- agentex/lib/cli/templates/default/Dockerfile.j2 +42 -0
- agentex/lib/cli/templates/default/README.md.j2 +193 -0
- agentex/lib/cli/templates/default/deploy/example.yaml.j2 +55 -0
- agentex/lib/cli/templates/default/manifest.yaml.j2 +116 -0
- agentex/lib/cli/templates/default/project/acp.py.j2 +29 -0
- agentex/lib/cli/templates/default/pyproject.toml.j2 +33 -0
- agentex/lib/cli/templates/default/requirements.txt.j2 +5 -0
- agentex/lib/cli/templates/deploy/Screenshot 2025-03-19 at 10.36.57/342/200/257AM.png +0 -0
- agentex/lib/cli/templates/deploy/example.yaml.j2 +55 -0
- agentex/lib/cli/templates/sync/.dockerignore.j2 +43 -0
- agentex/lib/cli/templates/sync/Dockerfile-uv.j2 +42 -0
- agentex/lib/cli/templates/sync/Dockerfile.j2 +42 -0
- agentex/lib/cli/templates/sync/README.md.j2 +293 -0
- agentex/lib/cli/templates/sync/deploy/example.yaml.j2 +55 -0
- agentex/lib/cli/templates/sync/manifest.yaml.j2 +116 -0
- agentex/lib/cli/templates/sync/project/acp.py.j2 +26 -0
- agentex/lib/cli/templates/sync/pyproject.toml.j2 +33 -0
- agentex/lib/cli/templates/sync/requirements.txt.j2 +5 -0
- agentex/lib/cli/templates/temporal/.dockerignore.j2 +43 -0
- agentex/lib/cli/templates/temporal/Dockerfile-uv.j2 +48 -0
- agentex/lib/cli/templates/temporal/Dockerfile.j2 +48 -0
- agentex/lib/cli/templates/temporal/README.md.j2 +316 -0
- agentex/lib/cli/templates/temporal/deploy/example.yaml.j2 +55 -0
- agentex/lib/cli/templates/temporal/manifest.yaml.j2 +137 -0
- agentex/lib/cli/templates/temporal/project/acp.py.j2 +30 -0
- agentex/lib/cli/templates/temporal/project/run_worker.py.j2 +33 -0
- agentex/lib/cli/templates/temporal/project/workflow.py.j2 +66 -0
- agentex/lib/cli/templates/temporal/pyproject.toml.j2 +34 -0
- agentex/lib/cli/templates/temporal/requirements.txt.j2 +5 -0
- agentex/lib/cli/utils/cli_utils.py +14 -0
- agentex/lib/cli/utils/credential_utils.py +103 -0
- agentex/lib/cli/utils/exceptions.py +6 -0
- agentex/lib/cli/utils/kubectl_utils.py +135 -0
- agentex/lib/cli/utils/kubernetes_secrets_utils.py +185 -0
- agentex/lib/core/__init__.py +0 -0
- agentex/lib/core/adapters/__init__.py +0 -0
- agentex/lib/core/adapters/llm/__init__.py +1 -0
- agentex/lib/core/adapters/llm/adapter_litellm.py +46 -0
- agentex/lib/core/adapters/llm/adapter_sgp.py +55 -0
- agentex/lib/core/adapters/llm/port.py +24 -0
- agentex/lib/core/adapters/streams/adapter_redis.py +128 -0
- agentex/lib/core/adapters/streams/port.py +50 -0
- agentex/lib/core/clients/__init__.py +1 -0
- agentex/lib/core/clients/temporal/__init__.py +0 -0
- agentex/lib/core/clients/temporal/temporal_client.py +181 -0
- agentex/lib/core/clients/temporal/types.py +47 -0
- agentex/lib/core/clients/temporal/utils.py +56 -0
- agentex/lib/core/services/__init__.py +0 -0
- agentex/lib/core/services/adk/__init__.py +0 -0
- agentex/lib/core/services/adk/acp/__init__.py +0 -0
- agentex/lib/core/services/adk/acp/acp.py +210 -0
- agentex/lib/core/services/adk/agent_task_tracker.py +85 -0
- agentex/lib/core/services/adk/agents.py +43 -0
- agentex/lib/core/services/adk/events.py +61 -0
- agentex/lib/core/services/adk/messages.py +164 -0
- agentex/lib/core/services/adk/providers/__init__.py +0 -0
- agentex/lib/core/services/adk/providers/litellm.py +256 -0
- agentex/lib/core/services/adk/providers/openai.py +723 -0
- agentex/lib/core/services/adk/providers/sgp.py +99 -0
- agentex/lib/core/services/adk/state.py +120 -0
- agentex/lib/core/services/adk/streaming.py +262 -0
- agentex/lib/core/services/adk/tasks.py +69 -0
- agentex/lib/core/services/adk/tracing.py +36 -0
- agentex/lib/core/services/adk/utils/__init__.py +0 -0
- agentex/lib/core/services/adk/utils/templating.py +58 -0
- agentex/lib/core/temporal/__init__.py +0 -0
- agentex/lib/core/temporal/activities/__init__.py +207 -0
- agentex/lib/core/temporal/activities/activity_helpers.py +37 -0
- agentex/lib/core/temporal/activities/adk/__init__.py +0 -0
- agentex/lib/core/temporal/activities/adk/acp/__init__.py +0 -0
- agentex/lib/core/temporal/activities/adk/acp/acp_activities.py +86 -0
- agentex/lib/core/temporal/activities/adk/agent_task_tracker_activities.py +76 -0
- agentex/lib/core/temporal/activities/adk/agents_activities.py +35 -0
- agentex/lib/core/temporal/activities/adk/events_activities.py +50 -0
- agentex/lib/core/temporal/activities/adk/messages_activities.py +94 -0
- agentex/lib/core/temporal/activities/adk/providers/__init__.py +0 -0
- agentex/lib/core/temporal/activities/adk/providers/litellm_activities.py +71 -0
- agentex/lib/core/temporal/activities/adk/providers/openai_activities.py +210 -0
- agentex/lib/core/temporal/activities/adk/providers/sgp_activities.py +42 -0
- agentex/lib/core/temporal/activities/adk/state_activities.py +85 -0
- agentex/lib/core/temporal/activities/adk/streaming_activities.py +33 -0
- agentex/lib/core/temporal/activities/adk/tasks_activities.py +48 -0
- agentex/lib/core/temporal/activities/adk/tracing_activities.py +55 -0
- agentex/lib/core/temporal/activities/adk/utils/__init__.py +0 -0
- agentex/lib/core/temporal/activities/adk/utils/templating_activities.py +41 -0
- agentex/lib/core/temporal/services/__init__.py +0 -0
- agentex/lib/core/temporal/services/temporal_task_service.py +69 -0
- agentex/lib/core/temporal/types/__init__.py +0 -0
- agentex/lib/core/temporal/types/workflow.py +5 -0
- agentex/lib/core/temporal/workers/__init__.py +0 -0
- agentex/lib/core/temporal/workers/worker.py +162 -0
- agentex/lib/core/temporal/workflows/workflow.py +26 -0
- agentex/lib/core/tracing/__init__.py +5 -0
- agentex/lib/core/tracing/processors/agentex_tracing_processor.py +117 -0
- agentex/lib/core/tracing/processors/sgp_tracing_processor.py +119 -0
- agentex/lib/core/tracing/processors/tracing_processor_interface.py +40 -0
- agentex/lib/core/tracing/trace.py +311 -0
- agentex/lib/core/tracing/tracer.py +70 -0
- agentex/lib/core/tracing/tracing_processor_manager.py +62 -0
- agentex/lib/environment_variables.py +87 -0
- agentex/lib/py.typed +0 -0
- agentex/lib/sdk/__init__.py +0 -0
- agentex/lib/sdk/config/__init__.py +0 -0
- agentex/lib/sdk/config/agent_config.py +61 -0
- agentex/lib/sdk/config/agent_manifest.py +219 -0
- agentex/lib/sdk/config/build_config.py +35 -0
- agentex/lib/sdk/config/deployment_config.py +117 -0
- agentex/lib/sdk/config/local_development_config.py +56 -0
- agentex/lib/sdk/config/project_config.py +103 -0
- agentex/lib/sdk/fastacp/__init__.py +3 -0
- agentex/lib/sdk/fastacp/base/base_acp_server.py +406 -0
- agentex/lib/sdk/fastacp/fastacp.py +74 -0
- agentex/lib/sdk/fastacp/impl/agentic_base_acp.py +72 -0
- agentex/lib/sdk/fastacp/impl/sync_acp.py +109 -0
- agentex/lib/sdk/fastacp/impl/temporal_acp.py +97 -0
- agentex/lib/sdk/fastacp/tests/README.md +297 -0
- agentex/lib/sdk/fastacp/tests/conftest.py +307 -0
- agentex/lib/sdk/fastacp/tests/pytest.ini +10 -0
- agentex/lib/sdk/fastacp/tests/run_tests.py +227 -0
- agentex/lib/sdk/fastacp/tests/test_base_acp_server.py +450 -0
- agentex/lib/sdk/fastacp/tests/test_fastacp_factory.py +344 -0
- agentex/lib/sdk/fastacp/tests/test_integration.py +477 -0
- agentex/lib/sdk/state_machine/__init__.py +6 -0
- agentex/lib/sdk/state_machine/noop_workflow.py +21 -0
- agentex/lib/sdk/state_machine/state.py +10 -0
- agentex/lib/sdk/state_machine/state_machine.py +189 -0
- agentex/lib/sdk/state_machine/state_workflow.py +16 -0
- agentex/lib/sdk/utils/__init__.py +0 -0
- agentex/lib/sdk/utils/messages.py +223 -0
- agentex/lib/types/__init__.py +0 -0
- agentex/lib/types/acp.py +94 -0
- agentex/lib/types/agent_configs.py +79 -0
- agentex/lib/types/agent_results.py +29 -0
- agentex/lib/types/credentials.py +34 -0
- agentex/lib/types/fastacp.py +61 -0
- agentex/lib/types/files.py +13 -0
- agentex/lib/types/json_rpc.py +49 -0
- agentex/lib/types/llm_messages.py +354 -0
- agentex/lib/types/task_message_updates.py +171 -0
- agentex/lib/types/tracing.py +34 -0
- agentex/lib/utils/__init__.py +0 -0
- agentex/lib/utils/completions.py +131 -0
- agentex/lib/utils/console.py +14 -0
- agentex/lib/utils/io.py +29 -0
- agentex/lib/utils/iterables.py +14 -0
- agentex/lib/utils/json_schema.py +23 -0
- agentex/lib/utils/logging.py +31 -0
- agentex/lib/utils/mcp.py +17 -0
- agentex/lib/utils/model_utils.py +46 -0
- agentex/lib/utils/parsing.py +15 -0
- agentex/lib/utils/regex.py +6 -0
- agentex/lib/utils/temporal.py +13 -0
- agentex/py.typed +0 -0
- agentex/resources/__init__.py +103 -0
- agentex/resources/agents.py +707 -0
- agentex/resources/events.py +294 -0
- agentex/resources/messages/__init__.py +33 -0
- agentex/resources/messages/batch.py +271 -0
- agentex/resources/messages/messages.py +492 -0
- agentex/resources/spans.py +557 -0
- agentex/resources/states.py +544 -0
- agentex/resources/tasks.py +615 -0
- agentex/resources/tracker.py +384 -0
- agentex/types/__init__.py +56 -0
- agentex/types/acp_type.py +7 -0
- agentex/types/agent.py +29 -0
- agentex/types/agent_list_params.py +13 -0
- agentex/types/agent_list_response.py +10 -0
- agentex/types/agent_rpc_by_name_params.py +21 -0
- agentex/types/agent_rpc_params.py +51 -0
- agentex/types/agent_rpc_params1.py +21 -0
- agentex/types/agent_rpc_response.py +20 -0
- agentex/types/agent_rpc_result.py +90 -0
- agentex/types/agent_task_tracker.py +34 -0
- agentex/types/data_content.py +30 -0
- agentex/types/data_content_param.py +31 -0
- agentex/types/data_delta.py +14 -0
- agentex/types/event.py +29 -0
- agentex/types/event_list_params.py +22 -0
- agentex/types/event_list_response.py +10 -0
- agentex/types/message_author.py +7 -0
- agentex/types/message_create_params.py +18 -0
- agentex/types/message_list_params.py +14 -0
- agentex/types/message_list_response.py +10 -0
- agentex/types/message_style.py +7 -0
- agentex/types/message_update_params.py +18 -0
- agentex/types/messages/__init__.py +8 -0
- agentex/types/messages/batch_create_params.py +16 -0
- agentex/types/messages/batch_create_response.py +10 -0
- agentex/types/messages/batch_update_params.py +16 -0
- agentex/types/messages/batch_update_response.py +10 -0
- agentex/types/shared/__init__.py +3 -0
- agentex/types/shared/task_message_update.py +83 -0
- agentex/types/span.py +36 -0
- agentex/types/span_create_params.py +40 -0
- agentex/types/span_list_params.py +12 -0
- agentex/types/span_list_response.py +10 -0
- agentex/types/span_update_params.py +37 -0
- agentex/types/state.py +25 -0
- agentex/types/state_create_params.py +16 -0
- agentex/types/state_list_params.py +16 -0
- agentex/types/state_list_response.py +10 -0
- agentex/types/state_update_params.py +16 -0
- agentex/types/task.py +23 -0
- agentex/types/task_delete_by_name_response.py +8 -0
- agentex/types/task_delete_response.py +8 -0
- agentex/types/task_list_response.py +10 -0
- agentex/types/task_message.py +33 -0
- agentex/types/task_message_content.py +16 -0
- agentex/types/task_message_content_param.py +17 -0
- agentex/types/task_message_delta.py +16 -0
- agentex/types/text_content.py +53 -0
- agentex/types/text_content_param.py +54 -0
- agentex/types/text_delta.py +14 -0
- agentex/types/tool_request_content.py +36 -0
- agentex/types/tool_request_content_param.py +37 -0
- agentex/types/tool_request_delta.py +18 -0
- agentex/types/tool_response_content.py +36 -0
- agentex/types/tool_response_content_param.py +36 -0
- agentex/types/tool_response_delta.py +18 -0
- agentex/types/tracker_list_params.py +16 -0
- agentex/types/tracker_list_response.py +10 -0
- agentex/types/tracker_update_params.py +19 -0
- agentex_sdk-0.1.0a6.dist-info/METADATA +426 -0
- agentex_sdk-0.1.0a6.dist-info/RECORD +289 -0
- agentex_sdk-0.1.0a6.dist-info/WHEEL +4 -0
- agentex_sdk-0.1.0a6.dist-info/entry_points.txt +2 -0
- agentex_sdk-0.1.0a6.dist-info/licenses/LICENSE +201 -0
@@ -0,0 +1,210 @@
|
|
1
|
+
# Standard library imports
|
2
|
+
from collections.abc import Callable
|
3
|
+
from contextlib import AsyncExitStack, asynccontextmanager
|
4
|
+
from enum import Enum
|
5
|
+
from typing import Any, Literal
|
6
|
+
|
7
|
+
from agents import RunResult, RunResultStreaming
|
8
|
+
from agents.mcp import MCPServerStdio, MCPServerStdioParams
|
9
|
+
from agents.model_settings import ModelSettings as OAIModelSettings
|
10
|
+
from agents.tool import FunctionTool as OAIFunctionTool
|
11
|
+
from mcp import StdioServerParameters
|
12
|
+
from openai.types.responses.response_includable import ResponseIncludable
|
13
|
+
from openai.types.shared.reasoning import Reasoning
|
14
|
+
from temporalio import activity
|
15
|
+
|
16
|
+
from agentex.lib.core.services.adk.providers.openai import OpenAIService
|
17
|
+
|
18
|
+
# Local imports
|
19
|
+
from agentex.lib.types.agent_results import (
|
20
|
+
SerializableRunResult,
|
21
|
+
SerializableRunResultStreaming,
|
22
|
+
)
|
23
|
+
|
24
|
+
# Third-party imports
|
25
|
+
from agentex.lib.types.tracing import BaseModelWithTraceParams
|
26
|
+
from agentex.lib.utils import logging
|
27
|
+
|
28
|
+
logger = logging.make_logger(__name__)
|
29
|
+
|
30
|
+
|
31
|
+
class OpenAIActivityName(str, Enum):
|
32
|
+
"""Names of OpenAI agent activities."""
|
33
|
+
|
34
|
+
RUN_AGENT = "run_agent"
|
35
|
+
RUN_AGENT_AUTO_SEND = "run_agent_auto_send"
|
36
|
+
# Note: RUN_AGENT_STREAMED is not supported in Temporal due to generator limitations
|
37
|
+
RUN_AGENT_STREAMED_AUTO_SEND = "run_agent_streamed_auto_send"
|
38
|
+
|
39
|
+
|
40
|
+
class FunctionTool(BaseModelWithTraceParams):
|
41
|
+
name: str
|
42
|
+
description: str
|
43
|
+
params_json_schema: dict[str, Any]
|
44
|
+
on_invoke_tool: Callable[[dict[str, Any]], Any]
|
45
|
+
strict_json_schema: bool = True
|
46
|
+
is_enabled: bool = True
|
47
|
+
|
48
|
+
def to_oai_function_tool(self) -> OAIFunctionTool:
|
49
|
+
return OAIFunctionTool(**self.model_dump(exclude=["trace_id", "parent_span_id"]))
|
50
|
+
|
51
|
+
|
52
|
+
class ModelSettings(BaseModelWithTraceParams):
|
53
|
+
temperature: float | None = None
|
54
|
+
top_p: float | None = None
|
55
|
+
frequency_penalty: float | None = None
|
56
|
+
presence_penalty: float | None = None
|
57
|
+
tool_choice: Literal["auto", "required", "none"] | str | None = None
|
58
|
+
parallel_tool_calls: bool | None = None
|
59
|
+
truncation: Literal["auto", "disabled"] | None = None
|
60
|
+
max_tokens: int | None = None
|
61
|
+
reasoning: Reasoning | None = None
|
62
|
+
metadata: dict[str, str] | None = None
|
63
|
+
store: bool | None = None
|
64
|
+
include_usage: bool | None = None
|
65
|
+
response_include: list[ResponseIncludable] | None = None
|
66
|
+
extra_body: dict[str, str] | None = None
|
67
|
+
extra_headers: dict[str, str] | None = None
|
68
|
+
extra_args: dict[str, Any] | None = None
|
69
|
+
|
70
|
+
def to_oai_model_settings(self) -> OAIModelSettings:
|
71
|
+
return OAIModelSettings(**self.model_dump(exclude=["trace_id", "parent_span_id"]))
|
72
|
+
|
73
|
+
|
74
|
+
class RunAgentParams(BaseModelWithTraceParams):
|
75
|
+
"""Parameters for running an agent without streaming."""
|
76
|
+
|
77
|
+
input_list: list[dict]
|
78
|
+
mcp_server_params: list[StdioServerParameters]
|
79
|
+
agent_name: str
|
80
|
+
agent_instructions: str
|
81
|
+
handoff_description: str | None = None
|
82
|
+
handoffs: list["RunAgentParams"] | None = None
|
83
|
+
model: str | None = None
|
84
|
+
model_settings: ModelSettings | None = None
|
85
|
+
tools: list[FunctionTool] | None = None
|
86
|
+
output_type: Any = None
|
87
|
+
tool_use_behavior: Literal["run_llm_again", "stop_on_first_tool"] = "run_llm_again"
|
88
|
+
mcp_timeout_seconds: int | None = None
|
89
|
+
|
90
|
+
|
91
|
+
class RunAgentAutoSendParams(RunAgentParams):
|
92
|
+
"""Parameters for running an agent with automatic TaskMessage creation."""
|
93
|
+
|
94
|
+
task_id: str
|
95
|
+
|
96
|
+
|
97
|
+
class RunAgentStreamedAutoSendParams(RunAgentParams):
|
98
|
+
"""Parameters for running an agent with streaming and automatic TaskMessage creation."""
|
99
|
+
|
100
|
+
task_id: str
|
101
|
+
|
102
|
+
|
103
|
+
@asynccontextmanager
|
104
|
+
async def mcp_server_context(mcp_server_params: list[StdioServerParameters]):
|
105
|
+
"""Context manager for MCP servers."""
|
106
|
+
servers: list[MCPServerStdio] = []
|
107
|
+
for params in mcp_server_params:
|
108
|
+
server = MCPServerStdio(
|
109
|
+
name=f"Server: {params.command}",
|
110
|
+
params=MCPServerStdioParams(**params.model_dump()),
|
111
|
+
cache_tools_list=True,
|
112
|
+
client_session_timeout_seconds=60,
|
113
|
+
)
|
114
|
+
servers.append(server)
|
115
|
+
|
116
|
+
async with AsyncExitStack() as stack:
|
117
|
+
for server in servers:
|
118
|
+
await stack.enter_async_context(server)
|
119
|
+
yield servers
|
120
|
+
|
121
|
+
|
122
|
+
class OpenAIActivities:
|
123
|
+
"""Activities for OpenAI agent operations."""
|
124
|
+
|
125
|
+
def __init__(self, openai_service: OpenAIService):
|
126
|
+
self._openai_service = openai_service
|
127
|
+
|
128
|
+
@activity.defn(name=OpenAIActivityName.RUN_AGENT)
|
129
|
+
async def run_agent(self, params: RunAgentParams) -> SerializableRunResult:
|
130
|
+
"""Run an agent without streaming or TaskMessage creation."""
|
131
|
+
result = await self._openai_service.run_agent(
|
132
|
+
input_list=params.input_list,
|
133
|
+
mcp_server_params=params.mcp_server_params,
|
134
|
+
agent_name=params.agent_name,
|
135
|
+
agent_instructions=params.agent_instructions,
|
136
|
+
trace_id=params.trace_id,
|
137
|
+
parent_span_id=params.parent_span_id,
|
138
|
+
handoff_description=params.handoff_description,
|
139
|
+
handoffs=params.handoffs,
|
140
|
+
model=params.model,
|
141
|
+
model_settings=params.model_settings,
|
142
|
+
tools=params.tools,
|
143
|
+
output_type=params.output_type,
|
144
|
+
tool_use_behavior=params.tool_use_behavior,
|
145
|
+
)
|
146
|
+
return self._to_serializable_run_result(result)
|
147
|
+
|
148
|
+
@activity.defn(name=OpenAIActivityName.RUN_AGENT_AUTO_SEND)
|
149
|
+
async def run_agent_auto_send(
|
150
|
+
self, params: RunAgentAutoSendParams
|
151
|
+
) -> SerializableRunResult:
|
152
|
+
"""Run an agent with automatic TaskMessage creation."""
|
153
|
+
result = await self._openai_service.run_agent_auto_send(
|
154
|
+
task_id=params.task_id,
|
155
|
+
input_list=params.input_list,
|
156
|
+
mcp_server_params=params.mcp_server_params,
|
157
|
+
agent_name=params.agent_name,
|
158
|
+
agent_instructions=params.agent_instructions,
|
159
|
+
trace_id=params.trace_id,
|
160
|
+
parent_span_id=params.parent_span_id,
|
161
|
+
handoff_description=params.handoff_description,
|
162
|
+
handoffs=params.handoffs,
|
163
|
+
model=params.model,
|
164
|
+
model_settings=params.model_settings,
|
165
|
+
tools=params.tools,
|
166
|
+
output_type=params.output_type,
|
167
|
+
tool_use_behavior=params.tool_use_behavior,
|
168
|
+
)
|
169
|
+
return self._to_serializable_run_result(result)
|
170
|
+
|
171
|
+
@activity.defn(name=OpenAIActivityName.RUN_AGENT_STREAMED_AUTO_SEND)
|
172
|
+
async def run_agent_streamed_auto_send(
|
173
|
+
self, params: RunAgentStreamedAutoSendParams
|
174
|
+
) -> SerializableRunResultStreaming:
|
175
|
+
"""Run an agent with streaming and automatic TaskMessage creation."""
|
176
|
+
result = await self._openai_service.run_agent_streamed_auto_send(
|
177
|
+
task_id=params.task_id,
|
178
|
+
input_list=params.input_list,
|
179
|
+
mcp_server_params=params.mcp_server_params,
|
180
|
+
agent_name=params.agent_name,
|
181
|
+
agent_instructions=params.agent_instructions,
|
182
|
+
trace_id=params.trace_id,
|
183
|
+
parent_span_id=params.parent_span_id,
|
184
|
+
handoff_description=params.handoff_description,
|
185
|
+
handoffs=params.handoffs,
|
186
|
+
model=params.model,
|
187
|
+
model_settings=params.model_settings,
|
188
|
+
tools=params.tools,
|
189
|
+
output_type=params.output_type,
|
190
|
+
tool_use_behavior=params.tool_use_behavior,
|
191
|
+
)
|
192
|
+
return self._to_serializable_run_result_streaming(result)
|
193
|
+
|
194
|
+
@staticmethod
|
195
|
+
def _to_serializable_run_result(result: RunResult) -> SerializableRunResult:
|
196
|
+
"""Convert RunResult to SerializableRunResult."""
|
197
|
+
return SerializableRunResult(
|
198
|
+
final_output=result.final_output,
|
199
|
+
final_input_list=result.to_input_list(),
|
200
|
+
)
|
201
|
+
|
202
|
+
@staticmethod
|
203
|
+
def _to_serializable_run_result_streaming(
|
204
|
+
result: RunResultStreaming,
|
205
|
+
) -> SerializableRunResultStreaming:
|
206
|
+
"""Convert RunResultStreaming to SerializableRunResultStreaming."""
|
207
|
+
return SerializableRunResultStreaming(
|
208
|
+
final_output=result.final_output,
|
209
|
+
final_input_list=result.to_input_list(),
|
210
|
+
)
|
@@ -0,0 +1,42 @@
|
|
1
|
+
from enum import Enum
|
2
|
+
|
3
|
+
from temporalio import activity
|
4
|
+
|
5
|
+
from agentex.lib.core.services.adk.providers.sgp import SGPService
|
6
|
+
from agentex.lib.types.files import FileContentResponse
|
7
|
+
from agentex.lib.types.tracing import BaseModelWithTraceParams
|
8
|
+
from agentex.lib.utils.logging import make_logger
|
9
|
+
|
10
|
+
logger = make_logger(__name__)
|
11
|
+
|
12
|
+
|
13
|
+
class SGPActivityName(str, Enum):
|
14
|
+
DOWNLOAD_FILE_CONTENT = "download-file-content"
|
15
|
+
|
16
|
+
|
17
|
+
class DownloadFileParams(BaseModelWithTraceParams):
|
18
|
+
file_id: str
|
19
|
+
filename: str
|
20
|
+
|
21
|
+
|
22
|
+
class SGPActivities:
|
23
|
+
def __init__(self, sgp_service: SGPService):
|
24
|
+
self.sgp_service = sgp_service
|
25
|
+
|
26
|
+
@activity.defn(name=SGPActivityName.DOWNLOAD_FILE_CONTENT)
|
27
|
+
async def download_file_content(self, params: DownloadFileParams) -> FileContentResponse:
|
28
|
+
"""
|
29
|
+
Download file content from SGP.
|
30
|
+
|
31
|
+
Args:
|
32
|
+
params: DownloadFileParams containing file_id and filename.
|
33
|
+
|
34
|
+
Returns:
|
35
|
+
FileContentResponse with mime_type and base64_content for constructing LLM input.
|
36
|
+
"""
|
37
|
+
return await self.sgp_service.download_file_content(
|
38
|
+
file_id=params.file_id,
|
39
|
+
filename=params.filename,
|
40
|
+
trace_id=params.trace_id,
|
41
|
+
parent_span_id=params.parent_span_id,
|
42
|
+
)
|
@@ -0,0 +1,85 @@
|
|
1
|
+
from enum import Enum
|
2
|
+
from typing import Any
|
3
|
+
|
4
|
+
from temporalio import activity
|
5
|
+
|
6
|
+
from agentex.lib.core.services.adk.state import StateService
|
7
|
+
from agentex.types.state import State
|
8
|
+
from agentex.lib.types.tracing import BaseModelWithTraceParams
|
9
|
+
from agentex.lib.utils.logging import make_logger
|
10
|
+
|
11
|
+
logger = make_logger(__name__)
|
12
|
+
|
13
|
+
|
14
|
+
class StateActivityName(str, Enum):
|
15
|
+
CREATE_STATE = "create-state"
|
16
|
+
GET_STATE = "get-state"
|
17
|
+
UPDATE_STATE = "update-state"
|
18
|
+
DELETE_STATE = "delete-state"
|
19
|
+
|
20
|
+
|
21
|
+
class CreateStateParams(BaseModelWithTraceParams):
|
22
|
+
task_id: str
|
23
|
+
agent_id: str
|
24
|
+
state: dict[str, Any]
|
25
|
+
|
26
|
+
|
27
|
+
class GetStateParams(BaseModelWithTraceParams):
|
28
|
+
state_id: str | None = None
|
29
|
+
task_id: str | None = None
|
30
|
+
agent_id: str | None = None
|
31
|
+
|
32
|
+
|
33
|
+
class UpdateStateParams(BaseModelWithTraceParams):
|
34
|
+
state_id: str
|
35
|
+
task_id: str
|
36
|
+
agent_id: str
|
37
|
+
state: dict[str, Any]
|
38
|
+
|
39
|
+
|
40
|
+
class DeleteStateParams(BaseModelWithTraceParams):
|
41
|
+
state_id: str
|
42
|
+
|
43
|
+
|
44
|
+
class StateActivities:
|
45
|
+
def __init__(self, state_service: StateService):
|
46
|
+
self._state_service = state_service
|
47
|
+
|
48
|
+
@activity.defn(name=StateActivityName.CREATE_STATE)
|
49
|
+
async def create_state(self, params: CreateStateParams) -> State:
|
50
|
+
return await self._state_service.create_state(
|
51
|
+
task_id=params.task_id,
|
52
|
+
agent_id=params.agent_id,
|
53
|
+
state=params.state,
|
54
|
+
trace_id=params.trace_id,
|
55
|
+
parent_span_id=params.parent_span_id,
|
56
|
+
)
|
57
|
+
|
58
|
+
@activity.defn(name=StateActivityName.GET_STATE)
|
59
|
+
async def get_state(self, params: GetStateParams) -> State | None:
|
60
|
+
return await self._state_service.get_state(
|
61
|
+
state_id=params.state_id,
|
62
|
+
task_id=params.task_id,
|
63
|
+
agent_id=params.agent_id,
|
64
|
+
trace_id=params.trace_id,
|
65
|
+
parent_span_id=params.parent_span_id,
|
66
|
+
)
|
67
|
+
|
68
|
+
@activity.defn(name=StateActivityName.UPDATE_STATE)
|
69
|
+
async def update_state(self, params: UpdateStateParams) -> State:
|
70
|
+
return await self._state_service.update_state(
|
71
|
+
state_id=params.state_id,
|
72
|
+
task_id=params.task_id,
|
73
|
+
agent_id=params.agent_id,
|
74
|
+
state=params.state,
|
75
|
+
trace_id=params.trace_id,
|
76
|
+
parent_span_id=params.parent_span_id,
|
77
|
+
)
|
78
|
+
|
79
|
+
@activity.defn(name=StateActivityName.DELETE_STATE)
|
80
|
+
async def delete_state(self, params: DeleteStateParams) -> State:
|
81
|
+
return await self._state_service.delete_state(
|
82
|
+
state_id=params.state_id,
|
83
|
+
trace_id=params.trace_id,
|
84
|
+
parent_span_id=params.parent_span_id,
|
85
|
+
)
|
@@ -0,0 +1,33 @@
|
|
1
|
+
from enum import Enum
|
2
|
+
|
3
|
+
from temporalio import activity
|
4
|
+
|
5
|
+
from agentex.lib.core.services.adk.streaming import StreamingService
|
6
|
+
from agentex.lib.types.task_message_updates import TaskMessageUpdate
|
7
|
+
from agentex.lib.utils.logging import make_logger
|
8
|
+
from agentex.lib.utils.model_utils import BaseModel
|
9
|
+
from agentex.lib.utils.temporal import heartbeat_if_in_workflow
|
10
|
+
|
11
|
+
logger = make_logger(__name__)
|
12
|
+
|
13
|
+
|
14
|
+
class StreamingActivityName(str, Enum):
|
15
|
+
STREAM_UPDATE = "stream-update"
|
16
|
+
|
17
|
+
|
18
|
+
class StreamUpdateParams(BaseModel):
|
19
|
+
update: TaskMessageUpdate
|
20
|
+
|
21
|
+
|
22
|
+
class StreamingActivities:
|
23
|
+
"""
|
24
|
+
Temporal activities for streaming events to clients (ADK pattern).
|
25
|
+
"""
|
26
|
+
|
27
|
+
def __init__(self, streaming_service: StreamingService):
|
28
|
+
self._streaming_service = streaming_service
|
29
|
+
|
30
|
+
@activity.defn(name=StreamingActivityName.STREAM_UPDATE)
|
31
|
+
async def stream_update(self, params: StreamUpdateParams) -> TaskMessageUpdate | None:
|
32
|
+
heartbeat_if_in_workflow("stream update")
|
33
|
+
return await self._streaming_service.stream_update(update=params.update)
|
@@ -0,0 +1,48 @@
|
|
1
|
+
from enum import Enum
|
2
|
+
|
3
|
+
from temporalio import activity
|
4
|
+
|
5
|
+
from agentex.lib.core.services.adk.tasks import TasksService
|
6
|
+
from agentex.types.task import Task
|
7
|
+
from agentex.lib.types.tracing import BaseModelWithTraceParams
|
8
|
+
from agentex.lib.utils.logging import make_logger
|
9
|
+
|
10
|
+
logger = make_logger(__name__)
|
11
|
+
|
12
|
+
|
13
|
+
class TasksActivityName(str, Enum):
|
14
|
+
GET_TASK = "get-task"
|
15
|
+
DELETE_TASK = "delete-task"
|
16
|
+
|
17
|
+
|
18
|
+
class GetTaskParams(BaseModelWithTraceParams):
|
19
|
+
task_id: str | None = None
|
20
|
+
task_name: str | None = None
|
21
|
+
|
22
|
+
|
23
|
+
class DeleteTaskParams(BaseModelWithTraceParams):
|
24
|
+
task_id: str | None = None
|
25
|
+
task_name: str | None = None
|
26
|
+
|
27
|
+
|
28
|
+
class TasksActivities:
|
29
|
+
def __init__(self, tasks_service: TasksService):
|
30
|
+
self._tasks_service = tasks_service
|
31
|
+
|
32
|
+
@activity.defn(name=TasksActivityName.GET_TASK)
|
33
|
+
async def get_task(self, params: GetTaskParams) -> Task | None:
|
34
|
+
return await self._tasks_service.get_task(
|
35
|
+
task_id=params.task_id,
|
36
|
+
task_name=params.task_name,
|
37
|
+
trace_id=params.trace_id,
|
38
|
+
parent_span_id=params.parent_span_id,
|
39
|
+
)
|
40
|
+
|
41
|
+
@activity.defn(name=TasksActivityName.DELETE_TASK)
|
42
|
+
async def delete_task(self, params: DeleteTaskParams) -> Task:
|
43
|
+
return await self._tasks_service.delete_task(
|
44
|
+
task_id=params.task_id,
|
45
|
+
task_name=params.task_name,
|
46
|
+
trace_id=params.trace_id,
|
47
|
+
parent_span_id=params.parent_span_id,
|
48
|
+
)
|
@@ -0,0 +1,55 @@
|
|
1
|
+
from enum import Enum
|
2
|
+
from typing import Any
|
3
|
+
|
4
|
+
from temporalio import activity
|
5
|
+
|
6
|
+
from agentex.lib.core.services.adk.tracing import TracingService
|
7
|
+
from agentex.types.span import Span
|
8
|
+
from agentex.lib.utils.logging import make_logger
|
9
|
+
from agentex.lib.utils.model_utils import BaseModel
|
10
|
+
|
11
|
+
logger = make_logger(__name__)
|
12
|
+
|
13
|
+
|
14
|
+
class TracingActivityName(str, Enum):
|
15
|
+
START_SPAN = "start-span"
|
16
|
+
END_SPAN = "end-span"
|
17
|
+
|
18
|
+
|
19
|
+
class StartSpanParams(BaseModel):
|
20
|
+
trace_id: str
|
21
|
+
parent_id: str | None = None
|
22
|
+
name: str
|
23
|
+
input: list[Any] | dict[str, Any] | BaseModel | None = None
|
24
|
+
data: list[Any] | dict[str, Any] | BaseModel | None = None
|
25
|
+
|
26
|
+
|
27
|
+
class EndSpanParams(BaseModel):
|
28
|
+
trace_id: str
|
29
|
+
span: Span
|
30
|
+
|
31
|
+
|
32
|
+
class TracingActivities:
|
33
|
+
"""
|
34
|
+
Temporal activities for tracing (spans), ADK pattern.
|
35
|
+
"""
|
36
|
+
|
37
|
+
def __init__(self, tracing_service: TracingService):
|
38
|
+
self._tracing_service = tracing_service
|
39
|
+
|
40
|
+
@activity.defn(name=TracingActivityName.START_SPAN)
|
41
|
+
async def start_span(self, params: StartSpanParams) -> Span | None:
|
42
|
+
return await self._tracing_service.start_span(
|
43
|
+
trace_id=params.trace_id,
|
44
|
+
parent_id=params.parent_id,
|
45
|
+
name=params.name,
|
46
|
+
input=params.input,
|
47
|
+
data=params.data,
|
48
|
+
)
|
49
|
+
|
50
|
+
@activity.defn(name=TracingActivityName.END_SPAN)
|
51
|
+
async def end_span(self, params: EndSpanParams) -> Span:
|
52
|
+
return await self._tracing_service.end_span(
|
53
|
+
trace_id=params.trace_id,
|
54
|
+
span=params.span,
|
55
|
+
)
|
File without changes
|
@@ -0,0 +1,41 @@
|
|
1
|
+
from enum import Enum
|
2
|
+
from typing import Any
|
3
|
+
|
4
|
+
from temporalio import activity
|
5
|
+
|
6
|
+
from agentex.lib.core.services.adk.utils.templating import TemplatingService
|
7
|
+
from agentex.lib.types.tracing import BaseModelWithTraceParams
|
8
|
+
|
9
|
+
|
10
|
+
class JinjaActivityName(str, Enum):
|
11
|
+
RENDER_JINJA = "render-jinja"
|
12
|
+
|
13
|
+
|
14
|
+
class RenderJinjaParams(BaseModelWithTraceParams):
|
15
|
+
"""Parameters for the Jinja activity"""
|
16
|
+
|
17
|
+
template: str
|
18
|
+
variables: dict[str, Any]
|
19
|
+
|
20
|
+
|
21
|
+
class TemplatingActivities:
|
22
|
+
def __init__(self, templating_service: TemplatingService):
|
23
|
+
self.templating_service = templating_service
|
24
|
+
|
25
|
+
@activity.defn(name=JinjaActivityName.RENDER_JINJA)
|
26
|
+
async def render_jinja(self, params: RenderJinjaParams) -> str:
|
27
|
+
"""
|
28
|
+
Activity that renders a Jinja template with the provided data.
|
29
|
+
|
30
|
+
Args:
|
31
|
+
params: JinjaParams containing the data and template string
|
32
|
+
|
33
|
+
Returns:
|
34
|
+
The rendered template as a string
|
35
|
+
"""
|
36
|
+
return await self.templating_service.render_jinja(
|
37
|
+
template=params.template,
|
38
|
+
variables=params.variables,
|
39
|
+
trace_id=params.trace_id,
|
40
|
+
parent_span_id=params.parent_span_id,
|
41
|
+
)
|
File without changes
|
@@ -0,0 +1,69 @@
|
|
1
|
+
from agentex.lib.core.clients.temporal.temporal_client import TemporalClient
|
2
|
+
from agentex.lib.core.clients.temporal.types import WorkflowState
|
3
|
+
from agentex.lib.core.temporal.types.workflow import SignalName
|
4
|
+
from agentex.lib.environment_variables import EnvironmentVariables
|
5
|
+
from agentex.lib.types.acp import CreateTaskParams
|
6
|
+
from agentex.lib.types.acp import SendEventParams
|
7
|
+
from agentex.types.agent import Agent
|
8
|
+
from agentex.types.event import Event
|
9
|
+
from agentex.types.task import Task
|
10
|
+
|
11
|
+
|
12
|
+
class TemporalTaskService:
|
13
|
+
"""
|
14
|
+
Submits Agent agent_tasks to the async runtime for execution.
|
15
|
+
"""
|
16
|
+
|
17
|
+
def __init__(
|
18
|
+
self,
|
19
|
+
temporal_client: TemporalClient,
|
20
|
+
env_vars: EnvironmentVariables,
|
21
|
+
):
|
22
|
+
self._temporal_client = temporal_client
|
23
|
+
self._env_vars = env_vars
|
24
|
+
|
25
|
+
async def submit_task(self, agent: Agent, task: Task) -> str:
|
26
|
+
"""
|
27
|
+
Submit a task to the async runtime for execution.
|
28
|
+
|
29
|
+
returns the workflow ID of the temporal workflow
|
30
|
+
"""
|
31
|
+
return await self._temporal_client.start_workflow(
|
32
|
+
workflow=self._env_vars.WORKFLOW_NAME,
|
33
|
+
arg=CreateTaskParams(
|
34
|
+
agent=agent,
|
35
|
+
task=task,
|
36
|
+
params=None,
|
37
|
+
),
|
38
|
+
id=task.id,
|
39
|
+
task_queue=self._env_vars.WORKFLOW_TASK_QUEUE,
|
40
|
+
)
|
41
|
+
|
42
|
+
async def get_state(self, task_id: str) -> WorkflowState:
|
43
|
+
"""
|
44
|
+
Get the task state from the async runtime.
|
45
|
+
"""
|
46
|
+
return await self._temporal_client.get_workflow_status(
|
47
|
+
workflow_id=task_id,
|
48
|
+
)
|
49
|
+
|
50
|
+
async def send_event(self, agent: Agent, task: Task, event: Event) -> None:
|
51
|
+
return await self._temporal_client.send_signal(
|
52
|
+
workflow_id=task.id,
|
53
|
+
signal=SignalName.RECEIVE_EVENT.value,
|
54
|
+
payload=SendEventParams(
|
55
|
+
agent=agent,
|
56
|
+
task=task,
|
57
|
+
event=event,
|
58
|
+
).model_dump(),
|
59
|
+
)
|
60
|
+
|
61
|
+
async def cancel(self, task_id: str) -> None:
|
62
|
+
return await self._temporal_client.cancel_workflow(
|
63
|
+
workflow_id=task_id,
|
64
|
+
)
|
65
|
+
|
66
|
+
async def terminate(self, task_id: str) -> None:
|
67
|
+
return await self._temporal_client.terminate_workflow(
|
68
|
+
workflow_id=task_id,
|
69
|
+
)
|
File without changes
|
File without changes
|