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,581 @@
|
|
|
1
|
+
"""Prompt models for AgentPool."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from collections.abc import Awaitable, Callable
|
|
6
|
+
from dataclasses import field
|
|
7
|
+
import inspect
|
|
8
|
+
import os
|
|
9
|
+
from typing import TYPE_CHECKING, Annotated, Any, Literal, Self, assert_never
|
|
10
|
+
|
|
11
|
+
from mcp.types import Prompt as MCPPrompt, PromptArgument
|
|
12
|
+
from pydantic import ConfigDict, Field
|
|
13
|
+
from pydantic_ai import BinaryContent, ImageUrl, SystemPromptPart, UserPromptPart
|
|
14
|
+
from schemez import Schema
|
|
15
|
+
from upathtools import UPath, to_upath
|
|
16
|
+
|
|
17
|
+
from agentpool.log import get_logger
|
|
18
|
+
from agentpool.mcp_server import MCPClient
|
|
19
|
+
from agentpool.utils import importing
|
|
20
|
+
from agentpool.utils.inspection import execute
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
if TYPE_CHECKING:
|
|
24
|
+
from collections.abc import Mapping
|
|
25
|
+
|
|
26
|
+
from fastmcp.prompts.prompt import FunctionPrompt, Prompt as FastMCPPrompt
|
|
27
|
+
from pydantic_ai import ModelRequestPart
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
logger = get_logger(__name__)
|
|
31
|
+
|
|
32
|
+
MessageContentType = Literal["text", "resource", "image_url", "image_base64"]
|
|
33
|
+
# Our internal role type (could include more roles)
|
|
34
|
+
MessageRole = Literal["system", "user", "assistant", "tool"]
|
|
35
|
+
|
|
36
|
+
type CompletionFunction = Callable[[str], list[str]]
|
|
37
|
+
"""Type for completion functions. Takes current value, returns possible completions."""
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class MessageContent(Schema):
|
|
41
|
+
"""Content item in a message."""
|
|
42
|
+
|
|
43
|
+
type: MessageContentType
|
|
44
|
+
content: str # The actual content (text/uri/url/base64)
|
|
45
|
+
alt_text: str | None = None # For images or resource descriptions
|
|
46
|
+
|
|
47
|
+
def to_pydantic(self) -> UserPromptPart:
|
|
48
|
+
"""Convert MessageContent to Pydantic model."""
|
|
49
|
+
if self.type == "text":
|
|
50
|
+
return UserPromptPart(self.content)
|
|
51
|
+
if self.type == "image_url":
|
|
52
|
+
return UserPromptPart([ImageUrl(self.content)])
|
|
53
|
+
if self.type == "image_base64":
|
|
54
|
+
bin_content = BinaryContent(self.content.encode(), media_type="image/jpeg")
|
|
55
|
+
return UserPromptPart([bin_content])
|
|
56
|
+
msg = "Unsupported content type"
|
|
57
|
+
raise ValueError(msg)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class PromptParameter(Schema):
|
|
61
|
+
"""Prompt argument with validation information."""
|
|
62
|
+
|
|
63
|
+
name: str
|
|
64
|
+
"""Name of the argument as used in the prompt."""
|
|
65
|
+
|
|
66
|
+
description: str | None = None
|
|
67
|
+
"""Human-readable description of the argument."""
|
|
68
|
+
|
|
69
|
+
required: bool = False
|
|
70
|
+
"""Whether this argument must be provided when formatting the prompt."""
|
|
71
|
+
|
|
72
|
+
default: Any | None = None
|
|
73
|
+
"""Default value if argument is optional."""
|
|
74
|
+
|
|
75
|
+
def to_mcp_argument(self) -> PromptArgument:
|
|
76
|
+
"""Convert to MCP PromptArgument."""
|
|
77
|
+
from mcp.types import PromptArgument
|
|
78
|
+
|
|
79
|
+
return PromptArgument(name=self.name, description=self.description, required=self.required)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
class PromptMessage(Schema):
|
|
83
|
+
"""A message in a prompt template."""
|
|
84
|
+
|
|
85
|
+
role: MessageRole
|
|
86
|
+
content: str | MessageContent | list[MessageContent] = ""
|
|
87
|
+
|
|
88
|
+
def get_text_content(self) -> str:
|
|
89
|
+
"""Get text content of message."""
|
|
90
|
+
match self.content:
|
|
91
|
+
case str():
|
|
92
|
+
return self.content
|
|
93
|
+
case MessageContent() if self.content.type == "text":
|
|
94
|
+
return self.content.content
|
|
95
|
+
case list() if self.content:
|
|
96
|
+
# Join text content items with space
|
|
97
|
+
text_items = [
|
|
98
|
+
item.content
|
|
99
|
+
for item in self.content
|
|
100
|
+
if isinstance(item, MessageContent) and item.type == "text"
|
|
101
|
+
]
|
|
102
|
+
return " ".join(text_items) if text_items else ""
|
|
103
|
+
case _:
|
|
104
|
+
return ""
|
|
105
|
+
|
|
106
|
+
def to_pydantic_parts(self) -> list[ModelRequestPart]:
|
|
107
|
+
match self.role:
|
|
108
|
+
case "system":
|
|
109
|
+
return [SystemPromptPart(str(self.content))]
|
|
110
|
+
case "user":
|
|
111
|
+
match self.content:
|
|
112
|
+
case str():
|
|
113
|
+
return [UserPromptPart(self.content)]
|
|
114
|
+
case MessageContent():
|
|
115
|
+
return [self.content.to_pydantic()]
|
|
116
|
+
case list():
|
|
117
|
+
return [i.to_pydantic() for i in self.content]
|
|
118
|
+
return []
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
class BasePrompt(Schema):
|
|
122
|
+
"""Base class for all prompts."""
|
|
123
|
+
|
|
124
|
+
name: str | None = Field(None, exclude=True)
|
|
125
|
+
"""Technical identifier (automatically set from config key during registration)."""
|
|
126
|
+
|
|
127
|
+
description: str
|
|
128
|
+
"""Human-readable description of what this prompt does."""
|
|
129
|
+
|
|
130
|
+
title: str | None = None
|
|
131
|
+
"""Title of the prompt."""
|
|
132
|
+
|
|
133
|
+
metadata: dict[str, Any] = Field(default_factory=dict)
|
|
134
|
+
"""Additional metadata for storing custom prompt information."""
|
|
135
|
+
# messages: list[PromptMessage]
|
|
136
|
+
|
|
137
|
+
async def format(self, arguments: dict[str, Any] | None = None) -> list[PromptMessage]:
|
|
138
|
+
"""Format this prompt with given arguments.
|
|
139
|
+
|
|
140
|
+
Args:
|
|
141
|
+
arguments: Optional argument values
|
|
142
|
+
|
|
143
|
+
Returns:
|
|
144
|
+
List of formatted messages
|
|
145
|
+
|
|
146
|
+
Raises:
|
|
147
|
+
ValueError: If required arguments are missing
|
|
148
|
+
"""
|
|
149
|
+
raise NotImplementedError
|
|
150
|
+
|
|
151
|
+
def to_mcp_prompt(self) -> MCPPrompt:
|
|
152
|
+
"""Convert to MCP Prompt."""
|
|
153
|
+
raise NotImplementedError
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
class StaticPrompt(BasePrompt):
|
|
157
|
+
"""Static prompt defined by message list."""
|
|
158
|
+
|
|
159
|
+
messages: list[PromptMessage]
|
|
160
|
+
"""List of messages that make up this prompt."""
|
|
161
|
+
|
|
162
|
+
type: Literal["text"] = Field("text", init=False)
|
|
163
|
+
"""Discriminator field identifying this as a static text prompt."""
|
|
164
|
+
|
|
165
|
+
arguments: list[PromptParameter] = Field(default_factory=list)
|
|
166
|
+
"""List of arguments that this prompt accepts."""
|
|
167
|
+
|
|
168
|
+
def validate_arguments(self, provided: dict[str, Any]) -> None:
|
|
169
|
+
"""Validate that required arguments are provided."""
|
|
170
|
+
required = {arg.name for arg in self.arguments if arg.required}
|
|
171
|
+
missing = required - set(provided)
|
|
172
|
+
if missing:
|
|
173
|
+
msg = f"Missing required arguments: {', '.join(missing)}"
|
|
174
|
+
raise ValueError(msg)
|
|
175
|
+
|
|
176
|
+
def to_mcp_prompt(self) -> MCPPrompt:
|
|
177
|
+
"""Convert to MCP Prompt."""
|
|
178
|
+
from mcp.types import Prompt as MCPPrompt
|
|
179
|
+
|
|
180
|
+
if self.name is None:
|
|
181
|
+
msg = "Prompt name not set. This should be set during registration."
|
|
182
|
+
raise ValueError(msg)
|
|
183
|
+
args = [arg.to_mcp_argument() for arg in self.arguments]
|
|
184
|
+
return MCPPrompt(name=self.name, description=self.description, arguments=args)
|
|
185
|
+
|
|
186
|
+
def to_fastmcp_prompt(self) -> FastMCPPrompt:
|
|
187
|
+
from fastmcp.prompts.prompt import (
|
|
188
|
+
Prompt as FastMCPPrompt,
|
|
189
|
+
PromptArgument as FastMCPArgument,
|
|
190
|
+
)
|
|
191
|
+
|
|
192
|
+
params = [
|
|
193
|
+
FastMCPArgument(name=p.name, description=p.description, required=p.required)
|
|
194
|
+
for p in self.arguments
|
|
195
|
+
]
|
|
196
|
+
return FastMCPPrompt(
|
|
197
|
+
name=self.name or "",
|
|
198
|
+
title=self.title,
|
|
199
|
+
description=self.description,
|
|
200
|
+
arguments=params,
|
|
201
|
+
icons=None,
|
|
202
|
+
tags=set(),
|
|
203
|
+
)
|
|
204
|
+
|
|
205
|
+
async def format(self, arguments: dict[str, Any] | None = None) -> list[PromptMessage]:
|
|
206
|
+
"""Format static prompt messages with arguments."""
|
|
207
|
+
args = arguments or {}
|
|
208
|
+
self.validate_arguments(args)
|
|
209
|
+
|
|
210
|
+
# Add default values for optional arguments
|
|
211
|
+
for arg in self.arguments:
|
|
212
|
+
if arg.name not in args and not arg.required:
|
|
213
|
+
args[arg.name] = arg.default if arg.default is not None else ""
|
|
214
|
+
|
|
215
|
+
# Format all messages
|
|
216
|
+
formatted_messages = []
|
|
217
|
+
for msg in self.messages:
|
|
218
|
+
match msg.content:
|
|
219
|
+
case str():
|
|
220
|
+
content: MessageContent | list[MessageContent] = MessageContent(
|
|
221
|
+
type="text", content=msg.content.format(**args)
|
|
222
|
+
)
|
|
223
|
+
case MessageContent() if msg.content.type == "text":
|
|
224
|
+
msg_content = msg.content.content.format(**args)
|
|
225
|
+
content = MessageContent(type="text", content=msg_content)
|
|
226
|
+
case list():
|
|
227
|
+
content = [
|
|
228
|
+
MessageContent(
|
|
229
|
+
type=item.type,
|
|
230
|
+
content=item.content.format(**args)
|
|
231
|
+
if item.type == "text"
|
|
232
|
+
else item.content,
|
|
233
|
+
alt_text=item.alt_text,
|
|
234
|
+
)
|
|
235
|
+
for item in msg.content
|
|
236
|
+
if isinstance(item, MessageContent)
|
|
237
|
+
]
|
|
238
|
+
case _:
|
|
239
|
+
content = msg.content
|
|
240
|
+
|
|
241
|
+
formatted_messages.append(PromptMessage(role=msg.role, content=content))
|
|
242
|
+
|
|
243
|
+
return formatted_messages
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
class DynamicPrompt(BasePrompt):
|
|
247
|
+
"""Dynamic prompt loaded from callable."""
|
|
248
|
+
|
|
249
|
+
import_path: str | Callable[..., str | Awaitable[str]]
|
|
250
|
+
"""Dotted import path to the callable that generates the prompt."""
|
|
251
|
+
|
|
252
|
+
template: str | None = None
|
|
253
|
+
"""Optional template string for formatting the callable's output."""
|
|
254
|
+
|
|
255
|
+
completions: dict[str, str] | None = None
|
|
256
|
+
"""Optional mapping of argument names to completion functions."""
|
|
257
|
+
|
|
258
|
+
type: Literal["function"] = Field("function", init=False)
|
|
259
|
+
"""Discriminator field identifying this as a function-based prompt."""
|
|
260
|
+
|
|
261
|
+
@property
|
|
262
|
+
def messages(self) -> list[PromptMessage]:
|
|
263
|
+
"""Get the template messages for this prompt.
|
|
264
|
+
|
|
265
|
+
Note: These are template messages - actual content will be populated
|
|
266
|
+
during format() when the callable is executed.
|
|
267
|
+
"""
|
|
268
|
+
template = self.template or "{result}"
|
|
269
|
+
sys_content = MessageContent(type="text", content=f"Content from {self.name}:")
|
|
270
|
+
user_content = MessageContent(type="text", content=template)
|
|
271
|
+
return [
|
|
272
|
+
PromptMessage(role="system", content=sys_content),
|
|
273
|
+
PromptMessage(role="user", content=user_content),
|
|
274
|
+
]
|
|
275
|
+
|
|
276
|
+
def to_fastmcp_prompt(self) -> FunctionPrompt:
|
|
277
|
+
from fastmcp.prompts.prompt import FunctionPrompt
|
|
278
|
+
|
|
279
|
+
return FunctionPrompt.from_function(self.fn, title=self.title, description=self.description)
|
|
280
|
+
|
|
281
|
+
@property
|
|
282
|
+
def fn(self) -> Callable[..., str | Awaitable[str]]:
|
|
283
|
+
if isinstance(self.import_path, str):
|
|
284
|
+
return importing.import_callable(self.import_path)
|
|
285
|
+
return self.import_path
|
|
286
|
+
|
|
287
|
+
def get_completion_functions(self) -> dict[str, CompletionFunction]:
|
|
288
|
+
"""Resolve completion function import paths and return a completion fn dict."""
|
|
289
|
+
completion_funcs: dict[str, CompletionFunction] = {}
|
|
290
|
+
if not self.completions:
|
|
291
|
+
return {}
|
|
292
|
+
for arg_name, import_path in self.completions.items():
|
|
293
|
+
try:
|
|
294
|
+
func = importing.import_callable(import_path)
|
|
295
|
+
completion_funcs[arg_name] = func
|
|
296
|
+
except ValueError:
|
|
297
|
+
msg = "Failed to import completion function for %s: %s"
|
|
298
|
+
logger.warning(msg, arg_name, import_path)
|
|
299
|
+
return completion_funcs
|
|
300
|
+
|
|
301
|
+
async def format(self, arguments: dict[str, Any] | None = None) -> list[PromptMessage]:
|
|
302
|
+
"""Format this prompt with given arguments."""
|
|
303
|
+
args = arguments or {}
|
|
304
|
+
try:
|
|
305
|
+
result: Any = await execute(self.fn, **args)
|
|
306
|
+
template = self.template or "{result}"
|
|
307
|
+
msg = template.format(result=result)
|
|
308
|
+
content = MessageContent(type="text", content=msg)
|
|
309
|
+
msg = f"Content from {self.name}:"
|
|
310
|
+
sys_content = MessageContent(type="text", content=msg)
|
|
311
|
+
return [
|
|
312
|
+
PromptMessage(role="system", content=sys_content),
|
|
313
|
+
PromptMessage(role="user", content=content),
|
|
314
|
+
]
|
|
315
|
+
except Exception as exc:
|
|
316
|
+
msg = f"Failed to execute prompt callable: {exc}"
|
|
317
|
+
raise ValueError(msg) from exc
|
|
318
|
+
|
|
319
|
+
@classmethod
|
|
320
|
+
def from_callable(
|
|
321
|
+
cls,
|
|
322
|
+
fn: Callable[..., Any] | str,
|
|
323
|
+
*,
|
|
324
|
+
name_override: str | None = None,
|
|
325
|
+
description_override: str | None = None,
|
|
326
|
+
template_override: str | None = None,
|
|
327
|
+
completions: Mapping[str, CompletionFunction] | None = None,
|
|
328
|
+
) -> DynamicPrompt:
|
|
329
|
+
"""Create a prompt from a callable.
|
|
330
|
+
|
|
331
|
+
Args:
|
|
332
|
+
fn: Function or import path to create prompt from
|
|
333
|
+
name_override: Optional override for prompt name
|
|
334
|
+
description_override: Optional override for prompt description
|
|
335
|
+
template_override: Optional override for message template
|
|
336
|
+
completions: Optional dict mapping argument names to completion functions
|
|
337
|
+
|
|
338
|
+
Returns:
|
|
339
|
+
DynamicPrompt instance
|
|
340
|
+
|
|
341
|
+
Raises:
|
|
342
|
+
ValueError: If callable cannot be imported or is invalid
|
|
343
|
+
"""
|
|
344
|
+
from docstring_parser import parse as parse_docstring
|
|
345
|
+
|
|
346
|
+
completions = completions or {}
|
|
347
|
+
if isinstance(fn, str):
|
|
348
|
+
fn = importing.import_callable(fn)
|
|
349
|
+
|
|
350
|
+
name = name_override or getattr(fn, "__name__", "unknown")
|
|
351
|
+
if docstring := inspect.getdoc(fn):
|
|
352
|
+
parsed = parse_docstring(docstring)
|
|
353
|
+
description = description_override or parsed.short_description
|
|
354
|
+
else:
|
|
355
|
+
description = description_override or f"Prompt from {name}"
|
|
356
|
+
|
|
357
|
+
from agentpool.utils.inspection import get_fn_qualname
|
|
358
|
+
|
|
359
|
+
path = f"{fn.__module__}.{get_fn_qualname(fn)}"
|
|
360
|
+
return cls(
|
|
361
|
+
name=name,
|
|
362
|
+
description=description or "",
|
|
363
|
+
import_path=path,
|
|
364
|
+
template=template_override,
|
|
365
|
+
metadata={"source": "function", "import_path": path},
|
|
366
|
+
)
|
|
367
|
+
|
|
368
|
+
def to_mcp_prompt(self) -> MCPPrompt:
|
|
369
|
+
"""Convert to MCP Prompt."""
|
|
370
|
+
from docstring_parser import parse as parse_docstring
|
|
371
|
+
from mcp.types import Prompt as MCPPrompt
|
|
372
|
+
|
|
373
|
+
sig = inspect.signature(self.fn)
|
|
374
|
+
# hints = get_type_hints(self.fn, include_extras=True, localns=locals())
|
|
375
|
+
if docstring := inspect.getdoc(self.fn):
|
|
376
|
+
parsed = parse_docstring(docstring)
|
|
377
|
+
# Create mapping of param names to descriptions
|
|
378
|
+
arg_docs = {
|
|
379
|
+
param.arg_name: param.description
|
|
380
|
+
for param in parsed.params
|
|
381
|
+
if param.arg_name and param.description
|
|
382
|
+
}
|
|
383
|
+
else:
|
|
384
|
+
arg_docs = {}
|
|
385
|
+
|
|
386
|
+
# Create arguments
|
|
387
|
+
arguments = []
|
|
388
|
+
for param_name, param in sig.parameters.items():
|
|
389
|
+
if param.kind in (param.VAR_POSITIONAL, param.VAR_KEYWORD):
|
|
390
|
+
continue
|
|
391
|
+
|
|
392
|
+
required = param.default == param.empty
|
|
393
|
+
arg = PromptParameter(
|
|
394
|
+
name=param_name,
|
|
395
|
+
description=arg_docs.get(param_name),
|
|
396
|
+
required=required,
|
|
397
|
+
default=None if param.default is param.empty else param.default,
|
|
398
|
+
)
|
|
399
|
+
arguments.append(arg)
|
|
400
|
+
|
|
401
|
+
if self.name is None:
|
|
402
|
+
msg = "Prompt name not set. This should be set during registration."
|
|
403
|
+
raise ValueError(msg)
|
|
404
|
+
args = [arg.to_mcp_argument() for arg in arguments]
|
|
405
|
+
return MCPPrompt(name=self.name, description=self.description, arguments=args)
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+
class MCPClientPrompt(BasePrompt):
|
|
409
|
+
"""A prompt that can be rendered from an MCP server."""
|
|
410
|
+
|
|
411
|
+
client: MCPClient
|
|
412
|
+
"""The client used to render the prompt."""
|
|
413
|
+
|
|
414
|
+
name: str
|
|
415
|
+
"""The name of the prompt."""
|
|
416
|
+
|
|
417
|
+
arguments: list[dict[str, Any]] = field(default_factory=list)
|
|
418
|
+
"""A list of arguments for the prompt."""
|
|
419
|
+
|
|
420
|
+
model_config = ConfigDict(arbitrary_types_allowed=True)
|
|
421
|
+
|
|
422
|
+
def to_mcp_prompt(self) -> MCPPrompt:
|
|
423
|
+
"""Convert to MCP Prompt."""
|
|
424
|
+
args = [
|
|
425
|
+
PromptArgument(name=i["name"], description=i["description"], required=i["required"])
|
|
426
|
+
for i in self.arguments
|
|
427
|
+
]
|
|
428
|
+
return MCPPrompt(name=self.name, description=self.description, arguments=args)
|
|
429
|
+
|
|
430
|
+
@classmethod
|
|
431
|
+
def from_fastmcp(cls, client: MCPClient, prompt: MCPPrompt) -> Self:
|
|
432
|
+
"""Convert MCP prompt to our Prompt class."""
|
|
433
|
+
arguments = [
|
|
434
|
+
{
|
|
435
|
+
"name": arg.name,
|
|
436
|
+
"description": arg.description,
|
|
437
|
+
"required": arg.required or False,
|
|
438
|
+
}
|
|
439
|
+
for arg in prompt.arguments or []
|
|
440
|
+
]
|
|
441
|
+
|
|
442
|
+
return cls(
|
|
443
|
+
name=prompt.name,
|
|
444
|
+
description=prompt.description or "",
|
|
445
|
+
arguments=arguments,
|
|
446
|
+
client=client,
|
|
447
|
+
)
|
|
448
|
+
|
|
449
|
+
def __repr__(self) -> str:
|
|
450
|
+
return f"Prompt(name={self.name!r}, description={self.description!r})"
|
|
451
|
+
|
|
452
|
+
async def get_components(
|
|
453
|
+
self, arguments: dict[str, str] | None = None
|
|
454
|
+
) -> list[SystemPromptPart | UserPromptPart]:
|
|
455
|
+
"""Get prompt as pydantic-ai message components.
|
|
456
|
+
|
|
457
|
+
Args:
|
|
458
|
+
arguments: Arguments to pass to the prompt template
|
|
459
|
+
|
|
460
|
+
Returns:
|
|
461
|
+
List of message parts ready for agent usage
|
|
462
|
+
|
|
463
|
+
Raises:
|
|
464
|
+
RuntimeError: If prompt fetch fails
|
|
465
|
+
ValueError: If prompt contains unsupported message types
|
|
466
|
+
"""
|
|
467
|
+
from agentpool.mcp_server.conversions import content_block_as_text
|
|
468
|
+
|
|
469
|
+
try:
|
|
470
|
+
result = await self.client.get_prompt(self.name, arguments)
|
|
471
|
+
except Exception as e:
|
|
472
|
+
msg = f"Failed to get prompt {self.name!r}: {e}"
|
|
473
|
+
raise RuntimeError(msg) from e
|
|
474
|
+
|
|
475
|
+
# Convert MCP messages to pydantic-ai parts
|
|
476
|
+
parts: list[SystemPromptPart | UserPromptPart] = []
|
|
477
|
+
for message in result.messages:
|
|
478
|
+
# Extract text content from MCP message
|
|
479
|
+
text_content = content_block_as_text(message.content)
|
|
480
|
+
# Convert based on role
|
|
481
|
+
match message.role:
|
|
482
|
+
case "user":
|
|
483
|
+
parts.append(UserPromptPart(content=text_content))
|
|
484
|
+
case "assistant":
|
|
485
|
+
# Convert assistant messages to user parts for context
|
|
486
|
+
parts.append(UserPromptPart(content=f"Assistant: {text_content}"))
|
|
487
|
+
case _ as unreachable:
|
|
488
|
+
assert_never(unreachable)
|
|
489
|
+
|
|
490
|
+
if not parts:
|
|
491
|
+
msg = f"No supported message parts found in prompt {self.name!r}"
|
|
492
|
+
raise ValueError(msg)
|
|
493
|
+
|
|
494
|
+
return parts
|
|
495
|
+
|
|
496
|
+
|
|
497
|
+
class FilePrompt(BasePrompt):
|
|
498
|
+
"""Prompt loaded from a file.
|
|
499
|
+
|
|
500
|
+
This type of prompt loads its content from a file, allowing for longer or more
|
|
501
|
+
complex prompts to be managed in separate files. The file content is loaded
|
|
502
|
+
and parsed according to the specified format.
|
|
503
|
+
"""
|
|
504
|
+
|
|
505
|
+
path: str | os.PathLike[str] | UPath
|
|
506
|
+
"""Path to the file containing the prompt content."""
|
|
507
|
+
|
|
508
|
+
fmt: Literal["text", "markdown", "jinja2"] = Field("text", alias="format")
|
|
509
|
+
"""Format of the file content (text, markdown, or jinja2 template)."""
|
|
510
|
+
|
|
511
|
+
type: Literal["file"] = Field("file", init=False)
|
|
512
|
+
"""Discriminator field identifying this as a file-based prompt."""
|
|
513
|
+
|
|
514
|
+
watch: bool = False
|
|
515
|
+
"""Whether to watch the file for changes and reload automatically."""
|
|
516
|
+
|
|
517
|
+
def to_mcp_prompt(self) -> MCPPrompt:
|
|
518
|
+
"""Convert to MCP Prompt."""
|
|
519
|
+
return MCPPrompt(
|
|
520
|
+
name=self.name or to_upath(self.path).name,
|
|
521
|
+
description=self.description,
|
|
522
|
+
)
|
|
523
|
+
|
|
524
|
+
@property
|
|
525
|
+
def messages(self) -> list[PromptMessage]:
|
|
526
|
+
"""Get messages from file content."""
|
|
527
|
+
content = to_upath(self.path).read_text("utf-8")
|
|
528
|
+
match self.fmt:
|
|
529
|
+
case "text":
|
|
530
|
+
# Simple text format - whole file as user message
|
|
531
|
+
msg = MessageContent(type="text", content=content)
|
|
532
|
+
case "markdown":
|
|
533
|
+
# TODO: Parse markdown sections into separate messages
|
|
534
|
+
msg = MessageContent(type="text", content=content)
|
|
535
|
+
case "jinja2":
|
|
536
|
+
# Raw template - will be formatted during format()
|
|
537
|
+
msg = MessageContent(type="text", content=content)
|
|
538
|
+
case _ as unreachable:
|
|
539
|
+
assert_never(unreachable)
|
|
540
|
+
return [PromptMessage(role="user", content=msg)]
|
|
541
|
+
|
|
542
|
+
async def format(self, arguments: dict[str, Any] | None = None) -> list[PromptMessage]:
|
|
543
|
+
"""Format the file content with arguments."""
|
|
544
|
+
args = arguments or {}
|
|
545
|
+
content = to_upath(self.path).read_text("utf-8")
|
|
546
|
+
|
|
547
|
+
if self.fmt == "jinja2":
|
|
548
|
+
# Use jinja2 for template formatting
|
|
549
|
+
import jinja2
|
|
550
|
+
|
|
551
|
+
env = jinja2.Environment(autoescape=True, enable_async=True)
|
|
552
|
+
template = env.from_string(content)
|
|
553
|
+
content = await template.render_async(**args)
|
|
554
|
+
else:
|
|
555
|
+
# Use simple string formatting
|
|
556
|
+
try:
|
|
557
|
+
content = content.format(**args)
|
|
558
|
+
except KeyError as exc:
|
|
559
|
+
msg = f"Missing argument in template: {exc}"
|
|
560
|
+
raise ValueError(msg) from exc
|
|
561
|
+
msg_content = MessageContent(type="text", content=content)
|
|
562
|
+
return [PromptMessage(role="user", content=msg_content)]
|
|
563
|
+
|
|
564
|
+
|
|
565
|
+
# Type to use in configuration
|
|
566
|
+
PromptType = Annotated[StaticPrompt | DynamicPrompt | FilePrompt, Field(discriminator="type")]
|
|
567
|
+
|
|
568
|
+
|
|
569
|
+
if __name__ == "__main__":
|
|
570
|
+
|
|
571
|
+
def prompt_fn() -> str:
|
|
572
|
+
return "hello"
|
|
573
|
+
|
|
574
|
+
async def main() -> None:
|
|
575
|
+
prompt = DynamicPrompt(import_path=prompt_fn, name="test", description="test")
|
|
576
|
+
result = await prompt.format()
|
|
577
|
+
print(result)
|
|
578
|
+
|
|
579
|
+
import anyio
|
|
580
|
+
|
|
581
|
+
anyio.run(main)
|
agentpool/py.typed
ADDED
|
File without changes
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
These scm files are all adapted from the github repositories listed here:
|
|
2
|
+
|
|
3
|
+
https://github.com/Goldziher/tree-sitter-language-pack/blob/main/sources/language_definitions.json
|
|
4
|
+
|
|
5
|
+
See this URL for information on the licenses of each repo:
|
|
6
|
+
|
|
7
|
+
https://github.com/Goldziher/tree-sitter-language-pack/
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
(struct_specifier name: (type_identifier) @name.definition.class body:(_)) @definition.class
|
|
2
|
+
|
|
3
|
+
(declaration type: (union_specifier name: (type_identifier) @name.definition.class)) @definition.class
|
|
4
|
+
|
|
5
|
+
(function_declarator declarator: (identifier) @name.definition.function) @definition.function
|
|
6
|
+
|
|
7
|
+
(type_definition declarator: (type_identifier) @name.definition.type) @definition.type
|
|
8
|
+
|
|
9
|
+
(enum_specifier name: (type_identifier) @name.definition.type) @definition.type
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
; Definitions
|
|
2
|
+
(intent_def
|
|
3
|
+
(intent) @name.definition.intent) @definition.intent
|
|
4
|
+
|
|
5
|
+
(slot_def
|
|
6
|
+
(slot) @name.definition.slot) @definition.slot
|
|
7
|
+
|
|
8
|
+
(alias_def
|
|
9
|
+
(alias) @name.definition.alias) @definition.alias
|
|
10
|
+
|
|
11
|
+
; References
|
|
12
|
+
(slot_ref
|
|
13
|
+
(slot) @name.reference.slot) @reference.slot
|
|
14
|
+
|
|
15
|
+
(alias_ref
|
|
16
|
+
(alias) @name.reference.alias) @reference.alias
|