agentpool 2.1.9__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.
Potentially problematic release.
This version of agentpool might be problematic. Click here for more details.
- acp/README.md +64 -0
- acp/__init__.py +172 -0
- acp/__main__.py +10 -0
- acp/acp_requests.py +285 -0
- acp/agent/__init__.py +6 -0
- acp/agent/connection.py +256 -0
- acp/agent/implementations/__init__.py +6 -0
- acp/agent/implementations/debug_server/__init__.py +1 -0
- acp/agent/implementations/debug_server/cli.py +79 -0
- acp/agent/implementations/debug_server/debug.html +234 -0
- acp/agent/implementations/debug_server/debug_server.py +496 -0
- acp/agent/implementations/testing.py +91 -0
- acp/agent/protocol.py +65 -0
- acp/bridge/README.md +162 -0
- acp/bridge/__init__.py +6 -0
- acp/bridge/__main__.py +91 -0
- acp/bridge/bridge.py +246 -0
- acp/bridge/py.typed +0 -0
- acp/bridge/settings.py +15 -0
- acp/client/__init__.py +7 -0
- acp/client/connection.py +251 -0
- acp/client/implementations/__init__.py +7 -0
- acp/client/implementations/default_client.py +185 -0
- acp/client/implementations/headless_client.py +266 -0
- acp/client/implementations/noop_client.py +110 -0
- acp/client/protocol.py +61 -0
- acp/connection.py +280 -0
- acp/exceptions.py +46 -0
- acp/filesystem.py +524 -0
- acp/notifications.py +832 -0
- acp/py.typed +0 -0
- acp/schema/__init__.py +265 -0
- acp/schema/agent_plan.py +30 -0
- acp/schema/agent_requests.py +126 -0
- acp/schema/agent_responses.py +256 -0
- acp/schema/base.py +39 -0
- acp/schema/capabilities.py +230 -0
- acp/schema/client_requests.py +247 -0
- acp/schema/client_responses.py +96 -0
- acp/schema/common.py +81 -0
- acp/schema/content_blocks.py +188 -0
- acp/schema/mcp.py +82 -0
- acp/schema/messages.py +171 -0
- acp/schema/notifications.py +82 -0
- acp/schema/protocol_stuff.md +3 -0
- acp/schema/session_state.py +160 -0
- acp/schema/session_updates.py +419 -0
- acp/schema/slash_commands.py +51 -0
- acp/schema/terminal.py +15 -0
- acp/schema/tool_call.py +347 -0
- acp/stdio.py +250 -0
- acp/task/__init__.py +53 -0
- acp/task/debug.py +197 -0
- acp/task/dispatcher.py +93 -0
- acp/task/queue.py +69 -0
- acp/task/sender.py +82 -0
- acp/task/state.py +87 -0
- acp/task/supervisor.py +93 -0
- acp/terminal_handle.py +30 -0
- acp/tool_call_reporter.py +199 -0
- acp/tool_call_state.py +178 -0
- acp/transports.py +104 -0
- acp/utils.py +240 -0
- agentpool/__init__.py +63 -0
- agentpool/__main__.py +7 -0
- agentpool/agents/__init__.py +30 -0
- agentpool/agents/acp_agent/__init__.py +5 -0
- agentpool/agents/acp_agent/acp_agent.py +837 -0
- agentpool/agents/acp_agent/acp_converters.py +294 -0
- agentpool/agents/acp_agent/client_handler.py +317 -0
- agentpool/agents/acp_agent/session_state.py +44 -0
- agentpool/agents/agent.py +1264 -0
- agentpool/agents/agui_agent/__init__.py +19 -0
- agentpool/agents/agui_agent/agui_agent.py +677 -0
- agentpool/agents/agui_agent/agui_converters.py +423 -0
- agentpool/agents/agui_agent/chunk_transformer.py +204 -0
- agentpool/agents/agui_agent/event_types.py +83 -0
- agentpool/agents/agui_agent/helpers.py +192 -0
- agentpool/agents/architect.py +71 -0
- agentpool/agents/base_agent.py +177 -0
- agentpool/agents/claude_code_agent/__init__.py +11 -0
- agentpool/agents/claude_code_agent/claude_code_agent.py +1021 -0
- agentpool/agents/claude_code_agent/converters.py +243 -0
- agentpool/agents/context.py +105 -0
- agentpool/agents/events/__init__.py +61 -0
- agentpool/agents/events/builtin_handlers.py +129 -0
- agentpool/agents/events/event_emitter.py +320 -0
- agentpool/agents/events/events.py +561 -0
- agentpool/agents/events/tts_handlers.py +186 -0
- agentpool/agents/interactions.py +419 -0
- agentpool/agents/slashed_agent.py +244 -0
- agentpool/agents/sys_prompts.py +178 -0
- agentpool/agents/tool_wrapping.py +184 -0
- agentpool/base_provider.py +28 -0
- agentpool/common_types.py +226 -0
- agentpool/config_resources/__init__.py +16 -0
- agentpool/config_resources/acp_assistant.yml +24 -0
- agentpool/config_resources/agents.yml +109 -0
- agentpool/config_resources/agents_template.yml +18 -0
- agentpool/config_resources/agui_test.yml +18 -0
- agentpool/config_resources/claude_code_agent.yml +16 -0
- agentpool/config_resources/claude_style_subagent.md +30 -0
- agentpool/config_resources/external_acp_agents.yml +77 -0
- agentpool/config_resources/opencode_style_subagent.md +19 -0
- agentpool/config_resources/tts_test_agents.yml +78 -0
- agentpool/delegation/__init__.py +8 -0
- agentpool/delegation/base_team.py +504 -0
- agentpool/delegation/message_flow_tracker.py +39 -0
- agentpool/delegation/pool.py +1129 -0
- agentpool/delegation/team.py +325 -0
- agentpool/delegation/teamrun.py +343 -0
- agentpool/docs/__init__.py +5 -0
- agentpool/docs/gen_examples.py +42 -0
- agentpool/docs/utils.py +370 -0
- agentpool/functional/__init__.py +20 -0
- agentpool/functional/py.typed +0 -0
- agentpool/functional/run.py +80 -0
- agentpool/functional/structure.py +136 -0
- agentpool/hooks/__init__.py +20 -0
- agentpool/hooks/agent_hooks.py +247 -0
- agentpool/hooks/base.py +119 -0
- agentpool/hooks/callable.py +140 -0
- agentpool/hooks/command.py +180 -0
- agentpool/hooks/prompt.py +122 -0
- agentpool/jinja_filters.py +132 -0
- agentpool/log.py +224 -0
- agentpool/mcp_server/__init__.py +17 -0
- agentpool/mcp_server/client.py +429 -0
- agentpool/mcp_server/constants.py +32 -0
- agentpool/mcp_server/conversions.py +172 -0
- agentpool/mcp_server/helpers.py +47 -0
- agentpool/mcp_server/manager.py +232 -0
- agentpool/mcp_server/message_handler.py +164 -0
- agentpool/mcp_server/registries/__init__.py +1 -0
- agentpool/mcp_server/registries/official_registry_client.py +345 -0
- agentpool/mcp_server/registries/pulsemcp_client.py +88 -0
- agentpool/mcp_server/tool_bridge.py +548 -0
- agentpool/messaging/__init__.py +58 -0
- agentpool/messaging/compaction.py +928 -0
- agentpool/messaging/connection_manager.py +319 -0
- agentpool/messaging/context.py +66 -0
- agentpool/messaging/event_manager.py +426 -0
- agentpool/messaging/events.py +39 -0
- agentpool/messaging/message_container.py +209 -0
- agentpool/messaging/message_history.py +491 -0
- agentpool/messaging/messagenode.py +377 -0
- agentpool/messaging/messages.py +655 -0
- agentpool/messaging/processing.py +76 -0
- agentpool/mime_utils.py +95 -0
- agentpool/models/__init__.py +21 -0
- agentpool/models/acp_agents/__init__.py +22 -0
- agentpool/models/acp_agents/base.py +308 -0
- agentpool/models/acp_agents/mcp_capable.py +790 -0
- agentpool/models/acp_agents/non_mcp.py +842 -0
- agentpool/models/agents.py +450 -0
- agentpool/models/agui_agents.py +89 -0
- agentpool/models/claude_code_agents.py +238 -0
- agentpool/models/file_agents.py +116 -0
- agentpool/models/file_parsing.py +367 -0
- agentpool/models/manifest.py +658 -0
- agentpool/observability/__init__.py +9 -0
- agentpool/observability/observability_registry.py +97 -0
- agentpool/prompts/__init__.py +1 -0
- agentpool/prompts/base.py +27 -0
- agentpool/prompts/builtin_provider.py +75 -0
- agentpool/prompts/conversion_manager.py +95 -0
- agentpool/prompts/convert.py +96 -0
- agentpool/prompts/manager.py +204 -0
- agentpool/prompts/parts/zed.md +33 -0
- agentpool/prompts/prompts.py +581 -0
- agentpool/py.typed +0 -0
- agentpool/queries/tree-sitter-language-pack/README.md +7 -0
- agentpool/queries/tree-sitter-language-pack/arduino-tags.scm +5 -0
- agentpool/queries/tree-sitter-language-pack/c-tags.scm +9 -0
- agentpool/queries/tree-sitter-language-pack/chatito-tags.scm +16 -0
- agentpool/queries/tree-sitter-language-pack/clojure-tags.scm +7 -0
- agentpool/queries/tree-sitter-language-pack/commonlisp-tags.scm +122 -0
- agentpool/queries/tree-sitter-language-pack/cpp-tags.scm +15 -0
- agentpool/queries/tree-sitter-language-pack/csharp-tags.scm +26 -0
- agentpool/queries/tree-sitter-language-pack/d-tags.scm +26 -0
- agentpool/queries/tree-sitter-language-pack/dart-tags.scm +92 -0
- agentpool/queries/tree-sitter-language-pack/elisp-tags.scm +5 -0
- agentpool/queries/tree-sitter-language-pack/elixir-tags.scm +54 -0
- agentpool/queries/tree-sitter-language-pack/elm-tags.scm +19 -0
- agentpool/queries/tree-sitter-language-pack/gleam-tags.scm +41 -0
- agentpool/queries/tree-sitter-language-pack/go-tags.scm +42 -0
- agentpool/queries/tree-sitter-language-pack/java-tags.scm +20 -0
- agentpool/queries/tree-sitter-language-pack/javascript-tags.scm +88 -0
- agentpool/queries/tree-sitter-language-pack/lua-tags.scm +34 -0
- agentpool/queries/tree-sitter-language-pack/matlab-tags.scm +10 -0
- agentpool/queries/tree-sitter-language-pack/ocaml-tags.scm +115 -0
- agentpool/queries/tree-sitter-language-pack/ocaml_interface-tags.scm +98 -0
- agentpool/queries/tree-sitter-language-pack/pony-tags.scm +39 -0
- agentpool/queries/tree-sitter-language-pack/properties-tags.scm +5 -0
- agentpool/queries/tree-sitter-language-pack/python-tags.scm +14 -0
- agentpool/queries/tree-sitter-language-pack/r-tags.scm +21 -0
- agentpool/queries/tree-sitter-language-pack/racket-tags.scm +12 -0
- agentpool/queries/tree-sitter-language-pack/ruby-tags.scm +64 -0
- agentpool/queries/tree-sitter-language-pack/rust-tags.scm +60 -0
- agentpool/queries/tree-sitter-language-pack/solidity-tags.scm +43 -0
- agentpool/queries/tree-sitter-language-pack/swift-tags.scm +51 -0
- agentpool/queries/tree-sitter-language-pack/udev-tags.scm +20 -0
- agentpool/queries/tree-sitter-languages/README.md +24 -0
- agentpool/queries/tree-sitter-languages/c-tags.scm +9 -0
- agentpool/queries/tree-sitter-languages/c_sharp-tags.scm +46 -0
- agentpool/queries/tree-sitter-languages/cpp-tags.scm +15 -0
- agentpool/queries/tree-sitter-languages/dart-tags.scm +91 -0
- agentpool/queries/tree-sitter-languages/elisp-tags.scm +8 -0
- agentpool/queries/tree-sitter-languages/elixir-tags.scm +54 -0
- agentpool/queries/tree-sitter-languages/elm-tags.scm +19 -0
- agentpool/queries/tree-sitter-languages/fortran-tags.scm +15 -0
- agentpool/queries/tree-sitter-languages/go-tags.scm +30 -0
- agentpool/queries/tree-sitter-languages/haskell-tags.scm +3 -0
- agentpool/queries/tree-sitter-languages/hcl-tags.scm +77 -0
- agentpool/queries/tree-sitter-languages/java-tags.scm +20 -0
- agentpool/queries/tree-sitter-languages/javascript-tags.scm +88 -0
- agentpool/queries/tree-sitter-languages/julia-tags.scm +60 -0
- agentpool/queries/tree-sitter-languages/kotlin-tags.scm +27 -0
- agentpool/queries/tree-sitter-languages/matlab-tags.scm +10 -0
- agentpool/queries/tree-sitter-languages/ocaml-tags.scm +115 -0
- agentpool/queries/tree-sitter-languages/ocaml_interface-tags.scm +98 -0
- agentpool/queries/tree-sitter-languages/php-tags.scm +26 -0
- agentpool/queries/tree-sitter-languages/python-tags.scm +12 -0
- agentpool/queries/tree-sitter-languages/ql-tags.scm +26 -0
- agentpool/queries/tree-sitter-languages/ruby-tags.scm +64 -0
- agentpool/queries/tree-sitter-languages/rust-tags.scm +60 -0
- agentpool/queries/tree-sitter-languages/scala-tags.scm +65 -0
- agentpool/queries/tree-sitter-languages/typescript-tags.scm +41 -0
- agentpool/queries/tree-sitter-languages/zig-tags.scm +3 -0
- agentpool/repomap.py +1231 -0
- agentpool/resource_providers/__init__.py +17 -0
- agentpool/resource_providers/aggregating.py +54 -0
- agentpool/resource_providers/base.py +172 -0
- agentpool/resource_providers/codemode/__init__.py +9 -0
- agentpool/resource_providers/codemode/code_executor.py +215 -0
- agentpool/resource_providers/codemode/default_prompt.py +19 -0
- agentpool/resource_providers/codemode/helpers.py +83 -0
- agentpool/resource_providers/codemode/progress_executor.py +212 -0
- agentpool/resource_providers/codemode/provider.py +150 -0
- agentpool/resource_providers/codemode/remote_mcp_execution.py +143 -0
- agentpool/resource_providers/codemode/remote_provider.py +171 -0
- agentpool/resource_providers/filtering.py +42 -0
- agentpool/resource_providers/mcp_provider.py +246 -0
- agentpool/resource_providers/plan_provider.py +196 -0
- agentpool/resource_providers/pool.py +69 -0
- agentpool/resource_providers/static.py +289 -0
- agentpool/running/__init__.py +20 -0
- agentpool/running/decorators.py +56 -0
- agentpool/running/discovery.py +101 -0
- agentpool/running/executor.py +284 -0
- agentpool/running/injection.py +111 -0
- agentpool/running/py.typed +0 -0
- agentpool/running/run_nodes.py +87 -0
- agentpool/server.py +122 -0
- agentpool/sessions/__init__.py +13 -0
- agentpool/sessions/manager.py +302 -0
- agentpool/sessions/models.py +71 -0
- agentpool/sessions/session.py +239 -0
- agentpool/sessions/store.py +163 -0
- agentpool/skills/__init__.py +5 -0
- agentpool/skills/manager.py +120 -0
- agentpool/skills/registry.py +210 -0
- agentpool/skills/skill.py +36 -0
- agentpool/storage/__init__.py +17 -0
- agentpool/storage/manager.py +419 -0
- agentpool/storage/serialization.py +136 -0
- agentpool/talk/__init__.py +13 -0
- agentpool/talk/registry.py +128 -0
- agentpool/talk/stats.py +159 -0
- agentpool/talk/talk.py +604 -0
- agentpool/tasks/__init__.py +20 -0
- agentpool/tasks/exceptions.py +25 -0
- agentpool/tasks/registry.py +33 -0
- agentpool/testing.py +129 -0
- agentpool/text_templates/__init__.py +39 -0
- agentpool/text_templates/system_prompt.jinja +30 -0
- agentpool/text_templates/tool_call_default.jinja +13 -0
- agentpool/text_templates/tool_call_markdown.jinja +25 -0
- agentpool/text_templates/tool_call_simple.jinja +5 -0
- agentpool/tools/__init__.py +16 -0
- agentpool/tools/base.py +269 -0
- agentpool/tools/exceptions.py +9 -0
- agentpool/tools/manager.py +255 -0
- agentpool/tools/tool_call_info.py +87 -0
- agentpool/ui/__init__.py +2 -0
- agentpool/ui/base.py +89 -0
- agentpool/ui/mock_provider.py +81 -0
- agentpool/ui/stdlib_provider.py +150 -0
- agentpool/utils/__init__.py +44 -0
- agentpool/utils/baseregistry.py +185 -0
- agentpool/utils/count_tokens.py +62 -0
- agentpool/utils/dag.py +184 -0
- agentpool/utils/importing.py +206 -0
- agentpool/utils/inspection.py +334 -0
- agentpool/utils/model_capabilities.py +25 -0
- agentpool/utils/network.py +28 -0
- agentpool/utils/now.py +22 -0
- agentpool/utils/parse_time.py +87 -0
- agentpool/utils/result_utils.py +35 -0
- agentpool/utils/signatures.py +305 -0
- agentpool/utils/streams.py +112 -0
- agentpool/utils/tasks.py +186 -0
- agentpool/vfs_registry.py +250 -0
- agentpool-2.1.9.dist-info/METADATA +336 -0
- agentpool-2.1.9.dist-info/RECORD +474 -0
- agentpool-2.1.9.dist-info/WHEEL +4 -0
- agentpool-2.1.9.dist-info/entry_points.txt +14 -0
- agentpool-2.1.9.dist-info/licenses/LICENSE +22 -0
- agentpool_cli/__init__.py +34 -0
- agentpool_cli/__main__.py +66 -0
- agentpool_cli/agent.py +175 -0
- agentpool_cli/cli_types.py +23 -0
- agentpool_cli/common.py +163 -0
- agentpool_cli/create.py +175 -0
- agentpool_cli/history.py +217 -0
- agentpool_cli/log.py +78 -0
- agentpool_cli/py.typed +0 -0
- agentpool_cli/run.py +84 -0
- agentpool_cli/serve_acp.py +177 -0
- agentpool_cli/serve_api.py +69 -0
- agentpool_cli/serve_mcp.py +74 -0
- agentpool_cli/serve_vercel.py +233 -0
- agentpool_cli/store.py +171 -0
- agentpool_cli/task.py +84 -0
- agentpool_cli/utils.py +104 -0
- agentpool_cli/watch.py +54 -0
- agentpool_commands/__init__.py +180 -0
- agentpool_commands/agents.py +199 -0
- agentpool_commands/base.py +45 -0
- agentpool_commands/commands.py +58 -0
- agentpool_commands/completers.py +110 -0
- agentpool_commands/connections.py +175 -0
- agentpool_commands/markdown_utils.py +31 -0
- agentpool_commands/models.py +62 -0
- agentpool_commands/prompts.py +78 -0
- agentpool_commands/py.typed +0 -0
- agentpool_commands/read.py +77 -0
- agentpool_commands/resources.py +210 -0
- agentpool_commands/session.py +48 -0
- agentpool_commands/tools.py +269 -0
- agentpool_commands/utils.py +189 -0
- agentpool_commands/workers.py +163 -0
- agentpool_config/__init__.py +53 -0
- agentpool_config/builtin_tools.py +265 -0
- agentpool_config/commands.py +237 -0
- agentpool_config/conditions.py +301 -0
- agentpool_config/converters.py +30 -0
- agentpool_config/durable.py +331 -0
- agentpool_config/event_handlers.py +600 -0
- agentpool_config/events.py +153 -0
- agentpool_config/forward_targets.py +251 -0
- agentpool_config/hook_conditions.py +331 -0
- agentpool_config/hooks.py +241 -0
- agentpool_config/jinja.py +206 -0
- agentpool_config/knowledge.py +41 -0
- agentpool_config/loaders.py +350 -0
- agentpool_config/mcp_server.py +243 -0
- agentpool_config/nodes.py +202 -0
- agentpool_config/observability.py +191 -0
- agentpool_config/output_types.py +55 -0
- agentpool_config/pool_server.py +267 -0
- agentpool_config/prompt_hubs.py +105 -0
- agentpool_config/prompts.py +185 -0
- agentpool_config/py.typed +0 -0
- agentpool_config/resources.py +33 -0
- agentpool_config/session.py +119 -0
- agentpool_config/skills.py +17 -0
- agentpool_config/storage.py +288 -0
- agentpool_config/system_prompts.py +190 -0
- agentpool_config/task.py +162 -0
- agentpool_config/teams.py +52 -0
- agentpool_config/tools.py +112 -0
- agentpool_config/toolsets.py +1033 -0
- agentpool_config/workers.py +86 -0
- agentpool_prompts/__init__.py +1 -0
- agentpool_prompts/braintrust_hub.py +235 -0
- agentpool_prompts/fabric.py +75 -0
- agentpool_prompts/langfuse_hub.py +79 -0
- agentpool_prompts/promptlayer_provider.py +59 -0
- agentpool_prompts/py.typed +0 -0
- agentpool_server/__init__.py +9 -0
- agentpool_server/a2a_server/__init__.py +5 -0
- agentpool_server/a2a_server/a2a_types.py +41 -0
- agentpool_server/a2a_server/server.py +190 -0
- agentpool_server/a2a_server/storage.py +81 -0
- agentpool_server/acp_server/__init__.py +22 -0
- agentpool_server/acp_server/acp_agent.py +786 -0
- agentpool_server/acp_server/acp_tools.py +43 -0
- agentpool_server/acp_server/commands/__init__.py +18 -0
- agentpool_server/acp_server/commands/acp_commands.py +594 -0
- agentpool_server/acp_server/commands/debug_commands.py +376 -0
- agentpool_server/acp_server/commands/docs_commands/__init__.py +39 -0
- agentpool_server/acp_server/commands/docs_commands/fetch_repo.py +169 -0
- agentpool_server/acp_server/commands/docs_commands/get_schema.py +176 -0
- agentpool_server/acp_server/commands/docs_commands/get_source.py +110 -0
- agentpool_server/acp_server/commands/docs_commands/git_diff.py +111 -0
- agentpool_server/acp_server/commands/docs_commands/helpers.py +33 -0
- agentpool_server/acp_server/commands/docs_commands/url_to_markdown.py +90 -0
- agentpool_server/acp_server/commands/spawn.py +210 -0
- agentpool_server/acp_server/converters.py +235 -0
- agentpool_server/acp_server/input_provider.py +338 -0
- agentpool_server/acp_server/server.py +288 -0
- agentpool_server/acp_server/session.py +969 -0
- agentpool_server/acp_server/session_manager.py +313 -0
- agentpool_server/acp_server/syntax_detection.py +250 -0
- agentpool_server/acp_server/zed_tools.md +90 -0
- agentpool_server/aggregating_server.py +309 -0
- agentpool_server/agui_server/__init__.py +11 -0
- agentpool_server/agui_server/server.py +128 -0
- agentpool_server/base.py +189 -0
- agentpool_server/http_server.py +164 -0
- agentpool_server/mcp_server/__init__.py +6 -0
- agentpool_server/mcp_server/server.py +314 -0
- agentpool_server/mcp_server/zed_wrapper.py +110 -0
- agentpool_server/openai_api_server/__init__.py +5 -0
- agentpool_server/openai_api_server/completions/__init__.py +1 -0
- agentpool_server/openai_api_server/completions/helpers.py +81 -0
- agentpool_server/openai_api_server/completions/models.py +98 -0
- agentpool_server/openai_api_server/responses/__init__.py +1 -0
- agentpool_server/openai_api_server/responses/helpers.py +74 -0
- agentpool_server/openai_api_server/responses/models.py +96 -0
- agentpool_server/openai_api_server/server.py +242 -0
- agentpool_server/py.typed +0 -0
- agentpool_storage/__init__.py +9 -0
- agentpool_storage/base.py +310 -0
- agentpool_storage/file_provider.py +378 -0
- agentpool_storage/formatters.py +129 -0
- agentpool_storage/memory_provider.py +396 -0
- agentpool_storage/models.py +108 -0
- agentpool_storage/py.typed +0 -0
- agentpool_storage/session_store.py +262 -0
- agentpool_storage/sql_provider/__init__.py +21 -0
- agentpool_storage/sql_provider/cli.py +146 -0
- agentpool_storage/sql_provider/models.py +249 -0
- agentpool_storage/sql_provider/queries.py +15 -0
- agentpool_storage/sql_provider/sql_provider.py +444 -0
- agentpool_storage/sql_provider/utils.py +234 -0
- agentpool_storage/text_log_provider.py +275 -0
- agentpool_toolsets/__init__.py +15 -0
- agentpool_toolsets/builtin/__init__.py +33 -0
- agentpool_toolsets/builtin/agent_management.py +239 -0
- agentpool_toolsets/builtin/chain.py +288 -0
- agentpool_toolsets/builtin/code.py +398 -0
- agentpool_toolsets/builtin/debug.py +291 -0
- agentpool_toolsets/builtin/execution_environment.py +381 -0
- agentpool_toolsets/builtin/file_edit/__init__.py +11 -0
- agentpool_toolsets/builtin/file_edit/file_edit.py +747 -0
- agentpool_toolsets/builtin/file_edit/fuzzy_matcher/__init__.py +5 -0
- agentpool_toolsets/builtin/file_edit/fuzzy_matcher/example_usage.py +311 -0
- agentpool_toolsets/builtin/file_edit/fuzzy_matcher/streaming_fuzzy_matcher.py +443 -0
- agentpool_toolsets/builtin/history.py +36 -0
- agentpool_toolsets/builtin/integration.py +85 -0
- agentpool_toolsets/builtin/skills.py +77 -0
- agentpool_toolsets/builtin/subagent_tools.py +324 -0
- agentpool_toolsets/builtin/tool_management.py +90 -0
- agentpool_toolsets/builtin/user_interaction.py +52 -0
- agentpool_toolsets/builtin/workers.py +128 -0
- agentpool_toolsets/composio_toolset.py +96 -0
- agentpool_toolsets/config_creation.py +192 -0
- agentpool_toolsets/entry_points.py +47 -0
- agentpool_toolsets/fsspec_toolset/__init__.py +7 -0
- agentpool_toolsets/fsspec_toolset/diagnostics.py +115 -0
- agentpool_toolsets/fsspec_toolset/grep.py +450 -0
- agentpool_toolsets/fsspec_toolset/helpers.py +631 -0
- agentpool_toolsets/fsspec_toolset/streaming_diff_parser.py +249 -0
- agentpool_toolsets/fsspec_toolset/toolset.py +1384 -0
- agentpool_toolsets/mcp_run_toolset.py +61 -0
- agentpool_toolsets/notifications.py +146 -0
- agentpool_toolsets/openapi.py +118 -0
- agentpool_toolsets/py.typed +0 -0
- agentpool_toolsets/search_toolset.py +202 -0
- agentpool_toolsets/semantic_memory_toolset.py +536 -0
- agentpool_toolsets/streaming_tools.py +265 -0
- agentpool_toolsets/vfs_toolset.py +124 -0
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
"""Function execution management."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
import importlib.util
|
|
7
|
+
import inspect
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
import sys
|
|
10
|
+
from typing import TYPE_CHECKING, Any, get_type_hints
|
|
11
|
+
|
|
12
|
+
import anyio
|
|
13
|
+
|
|
14
|
+
from agentpool.log import get_logger
|
|
15
|
+
from agentpool.running import with_nodes
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
if TYPE_CHECKING:
|
|
19
|
+
import os
|
|
20
|
+
|
|
21
|
+
from agentpool import AgentPool
|
|
22
|
+
from agentpool.running.discovery import NodeFunction
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
logger = get_logger(__name__)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class ExecutionError(Exception):
|
|
29
|
+
"""Raised when function execution fails."""
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def _validate_path(path: str | os.PathLike[str]) -> Path:
|
|
33
|
+
if str(path) == "__main__":
|
|
34
|
+
# Get the actual file being run
|
|
35
|
+
|
|
36
|
+
path = sys.modules["__main__"].__file__ # type: ignore
|
|
37
|
+
if not path:
|
|
38
|
+
msg = "Could not determine main module file"
|
|
39
|
+
raise ValueError(msg)
|
|
40
|
+
path_obj = Path(path)
|
|
41
|
+
if not path_obj.exists():
|
|
42
|
+
msg = f"Module not found: {path}"
|
|
43
|
+
raise ValueError(msg)
|
|
44
|
+
return path_obj
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def discover_functions(path: str | os.PathLike[str]) -> list[NodeFunction]:
|
|
48
|
+
"""Find all node functions in a module.
|
|
49
|
+
|
|
50
|
+
Args:
|
|
51
|
+
path: Path to Python module file
|
|
52
|
+
|
|
53
|
+
Returns:
|
|
54
|
+
List of discovered node functions
|
|
55
|
+
|
|
56
|
+
Raises:
|
|
57
|
+
ImportError: If module cannot be imported
|
|
58
|
+
ValueError: If path is invalid
|
|
59
|
+
"""
|
|
60
|
+
path_obj = _validate_path(path)
|
|
61
|
+
# Import module
|
|
62
|
+
spec = importlib.util.spec_from_file_location(path_obj.stem, path_obj)
|
|
63
|
+
if not spec or not spec.loader:
|
|
64
|
+
msg = f"Could not load module: {path}"
|
|
65
|
+
raise ImportError(msg)
|
|
66
|
+
|
|
67
|
+
module = importlib.util.module_from_spec(spec)
|
|
68
|
+
spec.loader.exec_module(module)
|
|
69
|
+
|
|
70
|
+
# Find decorated functions
|
|
71
|
+
return [i for name, i in inspect.getmembers(module) if hasattr(i, "_node_function")]
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def _sort_functions(functions: list[NodeFunction]) -> list[NodeFunction]:
|
|
75
|
+
"""Sort functions by order and dependencies.
|
|
76
|
+
|
|
77
|
+
Args:
|
|
78
|
+
functions: Functions to sort
|
|
79
|
+
|
|
80
|
+
Returns:
|
|
81
|
+
Sorted list of functions
|
|
82
|
+
|
|
83
|
+
Raises:
|
|
84
|
+
ValueError: If there are circular dependencies
|
|
85
|
+
"""
|
|
86
|
+
# First by explicit order
|
|
87
|
+
ordered = sorted(functions, key=lambda f: f.name)
|
|
88
|
+
|
|
89
|
+
# Then resolve dependencies
|
|
90
|
+
result = []
|
|
91
|
+
seen = set()
|
|
92
|
+
in_progress = set()
|
|
93
|
+
|
|
94
|
+
def add_function(func: NodeFunction) -> None:
|
|
95
|
+
if func.name in seen:
|
|
96
|
+
return
|
|
97
|
+
if func.name in in_progress:
|
|
98
|
+
msg = f"Circular dependency detected: {func.name}"
|
|
99
|
+
raise ValueError(msg)
|
|
100
|
+
|
|
101
|
+
in_progress.add(func.name)
|
|
102
|
+
# Add dependencies first
|
|
103
|
+
for dep in func.depends_on:
|
|
104
|
+
dep_fn = next((f for f in ordered if f.name == dep), None)
|
|
105
|
+
if not dep_fn:
|
|
106
|
+
msg = f"Missing dependency {dep} for {func.name}"
|
|
107
|
+
raise ValueError(msg)
|
|
108
|
+
add_function(dep_fn)
|
|
109
|
+
|
|
110
|
+
result.append(func)
|
|
111
|
+
in_progress.remove(func.name)
|
|
112
|
+
seen.add(func.name)
|
|
113
|
+
|
|
114
|
+
for func in ordered:
|
|
115
|
+
add_function(func)
|
|
116
|
+
|
|
117
|
+
return result
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def _group_parallel(
|
|
121
|
+
sorted_funcs: list[NodeFunction],
|
|
122
|
+
) -> list[list[NodeFunction]]:
|
|
123
|
+
"""Group functions that can run in parallel."""
|
|
124
|
+
if not sorted_funcs:
|
|
125
|
+
return []
|
|
126
|
+
|
|
127
|
+
# Group by dependency signature
|
|
128
|
+
by_deps: dict[tuple[str, ...], list[NodeFunction]] = {}
|
|
129
|
+
|
|
130
|
+
for func in sorted_funcs:
|
|
131
|
+
# Use tuple of sorted deps as key for consistent grouping
|
|
132
|
+
key = tuple(sorted(func.depends_on))
|
|
133
|
+
if key not in by_deps:
|
|
134
|
+
by_deps[key] = []
|
|
135
|
+
by_deps[key].append(func)
|
|
136
|
+
|
|
137
|
+
# Convert to list of groups, maintaining order
|
|
138
|
+
groups = []
|
|
139
|
+
seen_funcs: set[str] = set()
|
|
140
|
+
|
|
141
|
+
for func in sorted_funcs:
|
|
142
|
+
key = tuple(sorted(func.depends_on))
|
|
143
|
+
if func.name not in seen_funcs:
|
|
144
|
+
group = by_deps[key]
|
|
145
|
+
groups.append(group)
|
|
146
|
+
seen_funcs.update(f.name for f in group)
|
|
147
|
+
names = [[f.name for f in g] for g in groups]
|
|
148
|
+
logger.debug("Grouped functions into groups", num_funcs=len(sorted_funcs), group_names=names)
|
|
149
|
+
return groups
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
async def execute_single(
|
|
153
|
+
func: NodeFunction,
|
|
154
|
+
pool: AgentPool,
|
|
155
|
+
available_results: dict[str, Any],
|
|
156
|
+
inputs: dict[str, Any] | None = None,
|
|
157
|
+
) -> tuple[str, Any]:
|
|
158
|
+
"""Execute a single function.
|
|
159
|
+
|
|
160
|
+
Args:
|
|
161
|
+
func: Function to execute
|
|
162
|
+
pool: Agent pool for injection
|
|
163
|
+
available_results: Results from previous functions
|
|
164
|
+
inputs: Optional input overrides
|
|
165
|
+
|
|
166
|
+
Returns:
|
|
167
|
+
Tuple of (function name, result)
|
|
168
|
+
|
|
169
|
+
Raises:
|
|
170
|
+
ExecutionError: If execution fails
|
|
171
|
+
"""
|
|
172
|
+
logger.debug("Executing function", name=func.name)
|
|
173
|
+
try:
|
|
174
|
+
kwargs = func.default_inputs.copy()
|
|
175
|
+
if inputs:
|
|
176
|
+
kwargs.update(inputs)
|
|
177
|
+
|
|
178
|
+
# Get type hints for the function
|
|
179
|
+
hints = get_type_hints(func.func)
|
|
180
|
+
|
|
181
|
+
# Add and validate dependency results
|
|
182
|
+
for dep in func.depends_on:
|
|
183
|
+
if dep not in available_results:
|
|
184
|
+
msg = f"Missing result from {dep}"
|
|
185
|
+
raise ExecutionError(msg) # noqa: TRY301
|
|
186
|
+
|
|
187
|
+
value = available_results[dep]
|
|
188
|
+
if dep in hints: # If parameter is type hinted
|
|
189
|
+
_validate_value_type(value, hints[dep], func.name, dep)
|
|
190
|
+
kwargs[dep] = value
|
|
191
|
+
|
|
192
|
+
# Execute with node injection
|
|
193
|
+
wrapped = with_nodes(pool)(func.func)
|
|
194
|
+
result = await wrapped(**kwargs)
|
|
195
|
+
|
|
196
|
+
# Validate return type if hinted
|
|
197
|
+
if "return" in hints:
|
|
198
|
+
_validate_value_type(result, hints["return"], func.name, "return")
|
|
199
|
+
except Exception as e:
|
|
200
|
+
msg = f"Error executing {func.name}: {e}"
|
|
201
|
+
raise ExecutionError(msg) from e
|
|
202
|
+
else:
|
|
203
|
+
return func.name, result
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
def _validate_dependency_types(functions: list[NodeFunction]) -> None:
|
|
207
|
+
"""Validate that dependency types match return types."""
|
|
208
|
+
# Get return types for all functions
|
|
209
|
+
return_types = {}
|
|
210
|
+
for func in functions:
|
|
211
|
+
hints = get_type_hints(func.func)
|
|
212
|
+
if "return" in hints:
|
|
213
|
+
return_types[func.name] = hints["return"]
|
|
214
|
+
|
|
215
|
+
# Check each function's dependencies
|
|
216
|
+
for func in functions:
|
|
217
|
+
hints = get_type_hints(func.func)
|
|
218
|
+
for dep in func.depends_on:
|
|
219
|
+
# Only validate if both dependency return type AND parameter are typed
|
|
220
|
+
if dep in hints and dep in return_types:
|
|
221
|
+
expected_type = hints[dep]
|
|
222
|
+
provided_type = return_types[dep]
|
|
223
|
+
if expected_type != provided_type:
|
|
224
|
+
msg = (
|
|
225
|
+
f"Type mismatch in {func.name}: "
|
|
226
|
+
f"dependency {dep!r} is typed as {expected_type}, "
|
|
227
|
+
f"but {dep} returns {provided_type}"
|
|
228
|
+
)
|
|
229
|
+
raise TypeError(msg)
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
def _validate_value_type(value: Any, expected_type: type, func_name: str, param_name: str) -> None:
|
|
233
|
+
"""Validate that a value matches its expected type."""
|
|
234
|
+
if not isinstance(value, expected_type):
|
|
235
|
+
msg = (
|
|
236
|
+
f"Type error in {func_name}: parameter {param_name!r} "
|
|
237
|
+
f"expected {expected_type.__name__}, got {type(value).__name__}"
|
|
238
|
+
)
|
|
239
|
+
raise TypeError(msg)
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
async def execute_functions(
|
|
243
|
+
functions: list[NodeFunction],
|
|
244
|
+
pool: AgentPool,
|
|
245
|
+
inputs: dict[str, Any] | None = None,
|
|
246
|
+
parallel: bool = False,
|
|
247
|
+
) -> dict[str, Any]:
|
|
248
|
+
"""Execute discovered functions in the right order."""
|
|
249
|
+
msg = "Executing functions"
|
|
250
|
+
logger.info(msg, num_functions=len(functions), parallel=parallel)
|
|
251
|
+
results: dict[str, Any] = {}
|
|
252
|
+
# Sort by order/dependencies
|
|
253
|
+
sorted_funcs = _sort_functions(functions)
|
|
254
|
+
_validate_dependency_types(sorted_funcs)
|
|
255
|
+
|
|
256
|
+
if parallel:
|
|
257
|
+
# Group functions that can run in parallel
|
|
258
|
+
groups = _group_parallel(sorted_funcs)
|
|
259
|
+
for i, group in enumerate(groups):
|
|
260
|
+
logger.debug(
|
|
261
|
+
"Executing parallel group",
|
|
262
|
+
group=i + 1,
|
|
263
|
+
num_groups=len(groups),
|
|
264
|
+
names=[f.name for f in group],
|
|
265
|
+
)
|
|
266
|
+
|
|
267
|
+
# Ensure previous results are available
|
|
268
|
+
logger.debug("Available results", results=sorted(results))
|
|
269
|
+
# Run group in parallel
|
|
270
|
+
tasks = [execute_single(func, pool, results, inputs) for func in group]
|
|
271
|
+
group_results = await asyncio.gather(*tasks)
|
|
272
|
+
# Update results after group completes
|
|
273
|
+
results.update(dict(group_results))
|
|
274
|
+
logger.debug("Group complete", num=i + 1)
|
|
275
|
+
# Add small delay between groups to ensure timing separation
|
|
276
|
+
if i < len(groups) - 1:
|
|
277
|
+
await anyio.sleep(0.02) # 20ms between groups
|
|
278
|
+
else:
|
|
279
|
+
# Execute sequentially
|
|
280
|
+
for func in sorted_funcs:
|
|
281
|
+
name, result = await execute_single(func, pool, results, inputs)
|
|
282
|
+
results[name] = result
|
|
283
|
+
|
|
284
|
+
return results
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"""Agent injection utilities."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import inspect
|
|
6
|
+
import typing
|
|
7
|
+
from typing import TYPE_CHECKING, Any
|
|
8
|
+
|
|
9
|
+
from agentpool.log import get_logger
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
if TYPE_CHECKING:
|
|
13
|
+
from collections.abc import Callable
|
|
14
|
+
|
|
15
|
+
from agentpool import AgentPool, MessageNode
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
logger = get_logger(__name__)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def is_node_type(typ: Any) -> bool:
|
|
22
|
+
"""Check if a type is or inherits from MessageNode."""
|
|
23
|
+
from agentpool import MessageNode
|
|
24
|
+
|
|
25
|
+
if typ is MessageNode:
|
|
26
|
+
return True
|
|
27
|
+
|
|
28
|
+
# For "real" types
|
|
29
|
+
if isinstance(typ, type):
|
|
30
|
+
return issubclass(typ, MessageNode)
|
|
31
|
+
|
|
32
|
+
# For generic types (Agent[T], etc)
|
|
33
|
+
origin = getattr(typ, "__origin__", None)
|
|
34
|
+
if origin is not None and isinstance(origin, type):
|
|
35
|
+
return issubclass(origin, MessageNode)
|
|
36
|
+
|
|
37
|
+
return False
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class NodeInjectionError(Exception):
|
|
41
|
+
"""Raised when agent injection fails."""
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def inject_nodes[T, **P](
|
|
45
|
+
func: Callable[P, T],
|
|
46
|
+
pool: AgentPool,
|
|
47
|
+
provided_kwargs: dict[str, Any],
|
|
48
|
+
) -> dict[str, MessageNode[Any, Any]]:
|
|
49
|
+
"""Get nodes to inject based on function signature."""
|
|
50
|
+
hints = typing.get_type_hints(func)
|
|
51
|
+
params = inspect.signature(func).parameters
|
|
52
|
+
logger.debug("Injecting nodes", module=func.__module__, name=func.__qualname__, type_hint=hints)
|
|
53
|
+
|
|
54
|
+
nodes: dict[str, MessageNode[Any, Any]] = {}
|
|
55
|
+
for name, param in params.items():
|
|
56
|
+
if param.kind not in {
|
|
57
|
+
inspect.Parameter.POSITIONAL_OR_KEYWORD,
|
|
58
|
+
inspect.Parameter.KEYWORD_ONLY,
|
|
59
|
+
}:
|
|
60
|
+
logger.debug("Skippin: wrong parameter kind", name=name, kind=param.kind)
|
|
61
|
+
continue
|
|
62
|
+
|
|
63
|
+
hint = hints.get(name)
|
|
64
|
+
if hint is None:
|
|
65
|
+
logger.debug("Skipping: no type hint", name=name)
|
|
66
|
+
continue
|
|
67
|
+
|
|
68
|
+
# Handle Optional/Union types
|
|
69
|
+
origin = getattr(hint, "__origin__", None)
|
|
70
|
+
args = getattr(hint, "__args__", ())
|
|
71
|
+
|
|
72
|
+
# Check for MessageNode or any of its subclasses
|
|
73
|
+
is_node = (
|
|
74
|
+
is_node_type(hint) # Direct node type
|
|
75
|
+
or ( # Optional[Node[T]] or Union containing Node
|
|
76
|
+
origin is not None and any(is_node_type(arg) for arg in args)
|
|
77
|
+
)
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
if not is_node:
|
|
81
|
+
msg = "Skipping. Not a node type."
|
|
82
|
+
logger.debug(msg, name=name, hint=hint, origin=origin, args=args)
|
|
83
|
+
continue
|
|
84
|
+
|
|
85
|
+
logger.debug("Found node parameter", name=name)
|
|
86
|
+
|
|
87
|
+
# Check for duplicate parameters
|
|
88
|
+
if name in provided_kwargs and provided_kwargs[name] is not None:
|
|
89
|
+
msg = (
|
|
90
|
+
f"Cannot inject node {name!r}: Parameter already provided.\n"
|
|
91
|
+
f"Remove the explicit argument or rename the parameter."
|
|
92
|
+
)
|
|
93
|
+
logger.error(msg)
|
|
94
|
+
raise NodeInjectionError(msg)
|
|
95
|
+
|
|
96
|
+
# Get node from pool
|
|
97
|
+
if name not in pool.nodes:
|
|
98
|
+
available = ", ".join(sorted(pool.nodes))
|
|
99
|
+
msg = (
|
|
100
|
+
f"No node named {name!r} found in pool.\n"
|
|
101
|
+
f"Available nodes: {available}\n"
|
|
102
|
+
f"Check your YAML configuration or node name."
|
|
103
|
+
)
|
|
104
|
+
logger.error(msg)
|
|
105
|
+
raise NodeInjectionError(msg)
|
|
106
|
+
|
|
107
|
+
nodes[name] = pool.nodes[name]
|
|
108
|
+
logger.debug("Injecting node", node=nodes[name], name=name)
|
|
109
|
+
|
|
110
|
+
logger.debug("Injection complete.", nodes=sorted(nodes))
|
|
111
|
+
return nodes
|
|
File without changes
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"""Automatic agent function execution."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
from typing import TYPE_CHECKING, Any
|
|
7
|
+
|
|
8
|
+
from agentpool.running.executor import discover_functions, execute_functions
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
if TYPE_CHECKING:
|
|
12
|
+
from upathtools import JoinablePathLike
|
|
13
|
+
|
|
14
|
+
from agentpool.models.manifest import AgentsManifest
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
async def run_nodes_async(
|
|
18
|
+
config: JoinablePathLike | AgentsManifest,
|
|
19
|
+
*,
|
|
20
|
+
module: str | None = None,
|
|
21
|
+
functions: list[str] | None = None,
|
|
22
|
+
inputs: dict[str, Any] | None = None,
|
|
23
|
+
parallel: bool = False,
|
|
24
|
+
) -> dict[str, Any]:
|
|
25
|
+
"""Execute node functions with dependency handling.
|
|
26
|
+
|
|
27
|
+
Args:
|
|
28
|
+
config: Node configuration (path or manifest)
|
|
29
|
+
module: Optional module to discover functions from
|
|
30
|
+
functions: Optional list of function names to run (auto-discovers if None)
|
|
31
|
+
inputs: Optional input values for function parameters
|
|
32
|
+
parallel: Whether to run independent functions in parallel
|
|
33
|
+
|
|
34
|
+
Returns:
|
|
35
|
+
Dict mapping function names to their results
|
|
36
|
+
|
|
37
|
+
Example:
|
|
38
|
+
```python
|
|
39
|
+
@node_function
|
|
40
|
+
async def analyze(analyzer: Agent) -> str:
|
|
41
|
+
return await analyzer.run("...")
|
|
42
|
+
|
|
43
|
+
results = await run_nodes_async("agents.yml")
|
|
44
|
+
print(results["analyze"])
|
|
45
|
+
```
|
|
46
|
+
"""
|
|
47
|
+
from agentpool import AgentPool
|
|
48
|
+
|
|
49
|
+
# Find functions to run
|
|
50
|
+
if module:
|
|
51
|
+
discovered = discover_functions(module)
|
|
52
|
+
else:
|
|
53
|
+
# Use calling module
|
|
54
|
+
import inspect
|
|
55
|
+
|
|
56
|
+
frame = inspect.currentframe()
|
|
57
|
+
while frame:
|
|
58
|
+
if frame.f_globals.get("__name__") != __name__:
|
|
59
|
+
break
|
|
60
|
+
frame = frame.f_back
|
|
61
|
+
if not frame:
|
|
62
|
+
msg = "Could not determine calling module"
|
|
63
|
+
raise RuntimeError(msg)
|
|
64
|
+
discovered = discover_functions(frame.f_globals["__file__"])
|
|
65
|
+
|
|
66
|
+
if functions:
|
|
67
|
+
discovered = [f for f in discovered if f.name in functions]
|
|
68
|
+
|
|
69
|
+
# Run with pool
|
|
70
|
+
async with AgentPool(config) as pool:
|
|
71
|
+
return await execute_functions(discovered, pool, inputs=inputs, parallel=parallel)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def run_nodes(config: JoinablePathLike | AgentsManifest, **kwargs: Any) -> dict[str, Any]:
|
|
75
|
+
"""Run node functions synchronously.
|
|
76
|
+
|
|
77
|
+
Convenience wrapper around run_nodes_async for sync contexts.
|
|
78
|
+
See run_nodes_async for full documentation.
|
|
79
|
+
|
|
80
|
+
Args:
|
|
81
|
+
config: Agent configuration path
|
|
82
|
+
**kwargs: Arguments to pass to run_nodes_async
|
|
83
|
+
|
|
84
|
+
Returns:
|
|
85
|
+
Dict mapping function names to their results
|
|
86
|
+
"""
|
|
87
|
+
return asyncio.run(run_nodes_async(config, **kwargs))
|
agentpool/server.py
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"""Base classes for protocol bridge servers."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import abc
|
|
6
|
+
from typing import TYPE_CHECKING, Any, Self
|
|
7
|
+
|
|
8
|
+
from agentpool.log import get_logger
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
if TYPE_CHECKING:
|
|
12
|
+
from types import TracebackType
|
|
13
|
+
|
|
14
|
+
from agentpool import AgentPool
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
logger = get_logger(__name__)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class ServerBridge(abc.ABC):
|
|
21
|
+
"""Base class for AgentPool bridge servers.
|
|
22
|
+
|
|
23
|
+
Provides common lifecycle management, context manager protocol,
|
|
24
|
+
and running state handling for servers that bridge AgentPool agents
|
|
25
|
+
to external protocols (ACP, OpenAI API, MCP, etc.).
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
def __init__(self, pool: AgentPool[Any], **kwargs: Any) -> None:
|
|
29
|
+
"""Initialize the server bridge.
|
|
30
|
+
|
|
31
|
+
Args:
|
|
32
|
+
pool: Agent pool to expose via the protocol
|
|
33
|
+
**kwargs: Additional configuration options
|
|
34
|
+
"""
|
|
35
|
+
self._pool = pool
|
|
36
|
+
self._running = False
|
|
37
|
+
self._server_config = kwargs
|
|
38
|
+
|
|
39
|
+
@property
|
|
40
|
+
def is_running(self) -> bool:
|
|
41
|
+
"""Whether the server is currently running."""
|
|
42
|
+
return self._running
|
|
43
|
+
|
|
44
|
+
@property
|
|
45
|
+
def pool(self) -> AgentPool[Any]:
|
|
46
|
+
"""The underlying agent pool."""
|
|
47
|
+
return self._pool
|
|
48
|
+
|
|
49
|
+
async def run(self) -> None:
|
|
50
|
+
"""Run the server.
|
|
51
|
+
|
|
52
|
+
Template method that handles common lifecycle management
|
|
53
|
+
and delegates to subclass-specific _run() implementation.
|
|
54
|
+
|
|
55
|
+
Raises:
|
|
56
|
+
RuntimeError: If server is already running
|
|
57
|
+
"""
|
|
58
|
+
if self._running:
|
|
59
|
+
msg = "Server is already running"
|
|
60
|
+
raise RuntimeError(msg)
|
|
61
|
+
|
|
62
|
+
logger.info("Starting server", name=self.__class__.__name__)
|
|
63
|
+
self._running = True
|
|
64
|
+
|
|
65
|
+
try:
|
|
66
|
+
await self._run()
|
|
67
|
+
except Exception:
|
|
68
|
+
logger.exception("Server error")
|
|
69
|
+
raise
|
|
70
|
+
finally:
|
|
71
|
+
self._running = False
|
|
72
|
+
logger.info("Server stopped", name=self.__class__.__name__)
|
|
73
|
+
|
|
74
|
+
@abc.abstractmethod
|
|
75
|
+
async def _run(self) -> None:
|
|
76
|
+
"""Run the server implementation.
|
|
77
|
+
|
|
78
|
+
Subclasses must implement this method to handle their
|
|
79
|
+
specific protocol setup and serving logic.
|
|
80
|
+
"""
|
|
81
|
+
...
|
|
82
|
+
|
|
83
|
+
async def shutdown(self) -> None:
|
|
84
|
+
"""Shutdown the server.
|
|
85
|
+
|
|
86
|
+
Default implementation just sets running state to False.
|
|
87
|
+
Subclasses can override for custom cleanup logic.
|
|
88
|
+
"""
|
|
89
|
+
if self._running:
|
|
90
|
+
logger.info("Shutting down server", name=self.__class__.__name__)
|
|
91
|
+
self._running = False
|
|
92
|
+
|
|
93
|
+
async def __aenter__(self) -> Self:
|
|
94
|
+
"""Async context manager entry.
|
|
95
|
+
|
|
96
|
+
Default implementation does nothing. Subclasses can override
|
|
97
|
+
to perform initialization before the server starts.
|
|
98
|
+
|
|
99
|
+
Returns:
|
|
100
|
+
Self for fluent interface
|
|
101
|
+
"""
|
|
102
|
+
return self
|
|
103
|
+
|
|
104
|
+
async def __aexit__(
|
|
105
|
+
self,
|
|
106
|
+
exc_type: type[BaseException] | None,
|
|
107
|
+
exc_val: BaseException | None,
|
|
108
|
+
exc_tb: TracebackType | None,
|
|
109
|
+
) -> None:
|
|
110
|
+
"""Async context manager exit.
|
|
111
|
+
|
|
112
|
+
Default implementation calls shutdown() if server is running.
|
|
113
|
+
Subclasses can override for custom cleanup logic.
|
|
114
|
+
"""
|
|
115
|
+
if self._running:
|
|
116
|
+
await self.shutdown()
|
|
117
|
+
|
|
118
|
+
def __repr__(self) -> str:
|
|
119
|
+
"""String representation of the server."""
|
|
120
|
+
status = "running" if self._running else "stopped"
|
|
121
|
+
pool_info = f"pool-{len(self._pool.agents)}-agents"
|
|
122
|
+
return f"{self.__class__.__name__}({pool_info}, {status})"
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"""Session management package."""
|
|
2
|
+
|
|
3
|
+
from agentpool.sessions.models import SessionData
|
|
4
|
+
from agentpool.sessions.store import SessionStore
|
|
5
|
+
from agentpool.sessions.manager import SessionManager
|
|
6
|
+
from agentpool.sessions.session import ClientSession
|
|
7
|
+
|
|
8
|
+
__all__ = [
|
|
9
|
+
"ClientSession",
|
|
10
|
+
"SessionData",
|
|
11
|
+
"SessionManager",
|
|
12
|
+
"SessionStore",
|
|
13
|
+
]
|