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,491 @@
|
|
|
1
|
+
"""Conversation management for AgentPool."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
from collections import deque
|
|
7
|
+
from contextlib import asynccontextmanager
|
|
8
|
+
from dataclasses import dataclass, field
|
|
9
|
+
from typing import TYPE_CHECKING, Any, Self, assert_never
|
|
10
|
+
from uuid import UUID, uuid4
|
|
11
|
+
|
|
12
|
+
from psygnal import Signal
|
|
13
|
+
from upathtools import read_path, to_upath
|
|
14
|
+
|
|
15
|
+
from agentpool.log import get_logger
|
|
16
|
+
from agentpool.storage import StorageManager
|
|
17
|
+
from agentpool.utils.count_tokens import count_tokens
|
|
18
|
+
from agentpool.utils.now import get_now
|
|
19
|
+
from agentpool_config.session import SessionQuery
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
if TYPE_CHECKING:
|
|
23
|
+
from collections.abc import AsyncIterator, Coroutine, Sequence
|
|
24
|
+
from datetime import datetime
|
|
25
|
+
from types import TracebackType
|
|
26
|
+
|
|
27
|
+
from pydantic_ai import UserContent
|
|
28
|
+
from toprompt import AnyPromptType
|
|
29
|
+
from upathtools import JoinablePathLike
|
|
30
|
+
|
|
31
|
+
from agentpool.agents.agent import Agent
|
|
32
|
+
from agentpool.common_types import MessageRole, SessionIdType
|
|
33
|
+
from agentpool.messaging import ChatMessage
|
|
34
|
+
from agentpool.prompts.conversion_manager import ConversionManager
|
|
35
|
+
from agentpool.prompts.prompts import PromptType
|
|
36
|
+
from agentpool_config.session import MemoryConfig
|
|
37
|
+
|
|
38
|
+
logger = get_logger(__name__)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class MessageHistory:
|
|
42
|
+
"""Manages conversation state and system prompts."""
|
|
43
|
+
|
|
44
|
+
@dataclass(frozen=True)
|
|
45
|
+
class HistoryCleared:
|
|
46
|
+
"""Emitted when chat history is cleared."""
|
|
47
|
+
|
|
48
|
+
session_id: str
|
|
49
|
+
timestamp: datetime = field(default_factory=get_now)
|
|
50
|
+
|
|
51
|
+
history_cleared = Signal(HistoryCleared)
|
|
52
|
+
|
|
53
|
+
def __init__(
|
|
54
|
+
self,
|
|
55
|
+
storage: StorageManager | None = None,
|
|
56
|
+
converter: ConversionManager | None = None,
|
|
57
|
+
*,
|
|
58
|
+
messages: list[ChatMessage[Any]] | None = None,
|
|
59
|
+
session_config: MemoryConfig | None = None,
|
|
60
|
+
resources: Sequence[PromptType | str] = (),
|
|
61
|
+
) -> None:
|
|
62
|
+
"""Initialize conversation manager.
|
|
63
|
+
|
|
64
|
+
Args:
|
|
65
|
+
storage: Storage manager for persistence
|
|
66
|
+
converter: Content converter for file processing
|
|
67
|
+
messages: Optional list of initial messages
|
|
68
|
+
session_config: Optional MemoryConfig
|
|
69
|
+
resources: Optional paths to load as context
|
|
70
|
+
"""
|
|
71
|
+
from agentpool.messaging import ChatMessageList
|
|
72
|
+
from agentpool.prompts.conversion_manager import ConversionManager
|
|
73
|
+
from agentpool_config.storage import MemoryStorageConfig, StorageConfig
|
|
74
|
+
|
|
75
|
+
self._storage = storage or StorageManager(
|
|
76
|
+
config=StorageConfig(providers=[MemoryStorageConfig()])
|
|
77
|
+
)
|
|
78
|
+
self._converter = converter or ConversionManager([])
|
|
79
|
+
self.chat_messages = ChatMessageList()
|
|
80
|
+
if messages:
|
|
81
|
+
self.chat_messages.extend(messages)
|
|
82
|
+
self._last_messages: list[ChatMessage[Any]] = []
|
|
83
|
+
self._pending_parts: deque[UserContent] = deque()
|
|
84
|
+
self._config = session_config
|
|
85
|
+
self._resources = list(resources) # Store for async loading
|
|
86
|
+
# Generate new ID if none provided
|
|
87
|
+
self.id = str(uuid4())
|
|
88
|
+
|
|
89
|
+
if session_config and session_config.session:
|
|
90
|
+
self._current_history = self.storage.filter_messages.sync(session_config.session)
|
|
91
|
+
if session_config.session.name:
|
|
92
|
+
self.id = session_config.session.name
|
|
93
|
+
|
|
94
|
+
# Note: max_messages and max_tokens will be handled in add_message/get_history
|
|
95
|
+
# to maintain the rolling window during conversation
|
|
96
|
+
|
|
97
|
+
@property
|
|
98
|
+
def storage(self) -> StorageManager:
|
|
99
|
+
return self._storage
|
|
100
|
+
|
|
101
|
+
def get_initialization_tasks(self) -> list[Coroutine[Any, Any, Any]]:
|
|
102
|
+
"""Get all initialization coroutines."""
|
|
103
|
+
self._resources = [] # Clear so we dont load again on async init
|
|
104
|
+
return [self.load_context_source(source) for source in self._resources]
|
|
105
|
+
|
|
106
|
+
async def __aenter__(self) -> Self:
|
|
107
|
+
"""Initialize when used standalone."""
|
|
108
|
+
if tasks := self.get_initialization_tasks():
|
|
109
|
+
await asyncio.gather(*tasks)
|
|
110
|
+
return self
|
|
111
|
+
|
|
112
|
+
async def __aexit__(
|
|
113
|
+
self,
|
|
114
|
+
exc_type: type[BaseException] | None,
|
|
115
|
+
exc_val: BaseException | None,
|
|
116
|
+
exc_tb: TracebackType | None,
|
|
117
|
+
) -> None:
|
|
118
|
+
"""Clean up any pending parts."""
|
|
119
|
+
self._pending_parts.clear()
|
|
120
|
+
|
|
121
|
+
def __bool__(self) -> bool:
|
|
122
|
+
return bool(self._pending_parts) or bool(self.chat_messages)
|
|
123
|
+
|
|
124
|
+
def __repr__(self) -> str:
|
|
125
|
+
return f"MessageHistory(id={self.id!r})"
|
|
126
|
+
|
|
127
|
+
def __prompt__(self) -> str:
|
|
128
|
+
if not self.chat_messages:
|
|
129
|
+
return "No conversation history"
|
|
130
|
+
|
|
131
|
+
last_msgs = self.chat_messages[-2:]
|
|
132
|
+
parts = ["Recent conversation:"]
|
|
133
|
+
parts.extend(msg.format() for msg in last_msgs)
|
|
134
|
+
return "\n".join(parts)
|
|
135
|
+
|
|
136
|
+
def __contains__(self, item: Any) -> bool:
|
|
137
|
+
"""Check if item is in history."""
|
|
138
|
+
return item in self.chat_messages
|
|
139
|
+
|
|
140
|
+
def __len__(self) -> int:
|
|
141
|
+
"""Get length of history."""
|
|
142
|
+
return len(self.chat_messages)
|
|
143
|
+
|
|
144
|
+
def get_message_tokens(self, message: ChatMessage[Any]) -> int:
|
|
145
|
+
"""Get token count for a single message."""
|
|
146
|
+
content = "\n".join(message.format())
|
|
147
|
+
return count_tokens(content, message.model_name)
|
|
148
|
+
|
|
149
|
+
async def format_history(
|
|
150
|
+
self,
|
|
151
|
+
*,
|
|
152
|
+
max_tokens: int | None = None,
|
|
153
|
+
include_system: bool = False,
|
|
154
|
+
format_template: str | None = None,
|
|
155
|
+
num_messages: int | None = None, # Add this parameter
|
|
156
|
+
) -> str:
|
|
157
|
+
"""Format conversation history as a single context message.
|
|
158
|
+
|
|
159
|
+
Args:
|
|
160
|
+
max_tokens: Optional limit to include only last N tokens
|
|
161
|
+
include_system: Whether to include system messages
|
|
162
|
+
format_template: Optional custom format (defaults to agent/message pairs)
|
|
163
|
+
num_messages: Optional limit to include only last N messages
|
|
164
|
+
"""
|
|
165
|
+
template = format_template or "Agent {agent}: {content}\n"
|
|
166
|
+
messages: list[str] = []
|
|
167
|
+
token_count = 0
|
|
168
|
+
|
|
169
|
+
# Get messages, optionally limited
|
|
170
|
+
history: Sequence[ChatMessage[Any]] = self.chat_messages
|
|
171
|
+
if num_messages:
|
|
172
|
+
history = history[-num_messages:]
|
|
173
|
+
|
|
174
|
+
if max_tokens:
|
|
175
|
+
history = list(reversed(history)) # Start from newest when token limited
|
|
176
|
+
|
|
177
|
+
for msg in history:
|
|
178
|
+
name = msg.name or msg.role.title()
|
|
179
|
+
formatted = template.format(agent=name, content=str(msg.content))
|
|
180
|
+
|
|
181
|
+
if max_tokens:
|
|
182
|
+
# Count tokens in this message
|
|
183
|
+
if msg.cost_info:
|
|
184
|
+
msg_tokens = msg.cost_info.token_usage.total_tokens
|
|
185
|
+
else:
|
|
186
|
+
# Fallback to tiktoken if no cost info
|
|
187
|
+
msg_tokens = self.get_message_tokens(msg)
|
|
188
|
+
|
|
189
|
+
if token_count + msg_tokens > max_tokens:
|
|
190
|
+
break
|
|
191
|
+
token_count += msg_tokens
|
|
192
|
+
# Add to front since we're going backwards
|
|
193
|
+
messages.insert(0, formatted)
|
|
194
|
+
else:
|
|
195
|
+
messages.append(formatted)
|
|
196
|
+
|
|
197
|
+
return "\n".join(messages)
|
|
198
|
+
|
|
199
|
+
async def load_context_source(self, source: PromptType | str) -> None:
|
|
200
|
+
"""Load context from a single source."""
|
|
201
|
+
from agentpool.prompts.prompts import BasePrompt
|
|
202
|
+
|
|
203
|
+
try:
|
|
204
|
+
match source:
|
|
205
|
+
case str():
|
|
206
|
+
await self.add_context_from_path(source)
|
|
207
|
+
case BasePrompt():
|
|
208
|
+
await self.add_context_from_prompt(source)
|
|
209
|
+
except Exception:
|
|
210
|
+
logger.exception(
|
|
211
|
+
"Failed to load context",
|
|
212
|
+
source="file" if isinstance(source, str) else source.type,
|
|
213
|
+
)
|
|
214
|
+
|
|
215
|
+
def load_history_from_database(
|
|
216
|
+
self,
|
|
217
|
+
session: SessionIdType | SessionQuery = None,
|
|
218
|
+
*,
|
|
219
|
+
since: datetime | None = None,
|
|
220
|
+
until: datetime | None = None,
|
|
221
|
+
roles: set[MessageRole] | None = None,
|
|
222
|
+
limit: int | None = None,
|
|
223
|
+
) -> None:
|
|
224
|
+
"""Load conversation history from database.
|
|
225
|
+
|
|
226
|
+
Args:
|
|
227
|
+
session: Session ID or query config
|
|
228
|
+
since: Only include messages after this time (override)
|
|
229
|
+
until: Only include messages before this time (override)
|
|
230
|
+
roles: Only include messages with these roles (override)
|
|
231
|
+
limit: Maximum number of messages to return (override)
|
|
232
|
+
"""
|
|
233
|
+
from agentpool_config.session import SessionQuery
|
|
234
|
+
|
|
235
|
+
match session:
|
|
236
|
+
case SessionQuery() as query:
|
|
237
|
+
# Override query params if provided
|
|
238
|
+
if since is not None or until is not None or roles or limit:
|
|
239
|
+
update = {
|
|
240
|
+
"since": since.isoformat() if since else None,
|
|
241
|
+
"until": until.isoformat() if until else None,
|
|
242
|
+
"roles": roles,
|
|
243
|
+
"limit": limit,
|
|
244
|
+
}
|
|
245
|
+
query = query.model_copy(update=update)
|
|
246
|
+
if query.name:
|
|
247
|
+
self.id = query.name
|
|
248
|
+
case str() | UUID():
|
|
249
|
+
self.id = str(session)
|
|
250
|
+
query = SessionQuery(
|
|
251
|
+
name=self.id,
|
|
252
|
+
since=since.isoformat() if since else None,
|
|
253
|
+
until=until.isoformat() if until else None,
|
|
254
|
+
roles=roles,
|
|
255
|
+
limit=limit,
|
|
256
|
+
)
|
|
257
|
+
case None:
|
|
258
|
+
# Use current session ID
|
|
259
|
+
query = SessionQuery(
|
|
260
|
+
name=self.id,
|
|
261
|
+
since=since.isoformat() if since else None,
|
|
262
|
+
until=until.isoformat() if until else None,
|
|
263
|
+
roles=roles,
|
|
264
|
+
limit=limit,
|
|
265
|
+
)
|
|
266
|
+
case _ as unreachable:
|
|
267
|
+
assert_never(unreachable)
|
|
268
|
+
self.chat_messages.clear()
|
|
269
|
+
self.chat_messages.extend(self.storage.filter_messages.sync(query))
|
|
270
|
+
|
|
271
|
+
def get_history(
|
|
272
|
+
self,
|
|
273
|
+
do_filter: bool = True,
|
|
274
|
+
) -> list[ChatMessage[Any]]:
|
|
275
|
+
"""Get conversation history.
|
|
276
|
+
|
|
277
|
+
Args:
|
|
278
|
+
do_filter: Whether to apply memory config limits (max_tokens, max_messages)
|
|
279
|
+
|
|
280
|
+
Returns:
|
|
281
|
+
Filtered list of messages in chronological order
|
|
282
|
+
"""
|
|
283
|
+
# Start with original history
|
|
284
|
+
history: Sequence[ChatMessage[Any]] = self.chat_messages
|
|
285
|
+
|
|
286
|
+
# 3. Only filter if needed
|
|
287
|
+
if do_filter and self._config:
|
|
288
|
+
# First filter by message count (simple slice)
|
|
289
|
+
if self._config.max_messages:
|
|
290
|
+
history = history[-self._config.max_messages :]
|
|
291
|
+
|
|
292
|
+
# Then filter by tokens if needed
|
|
293
|
+
if self._config.max_tokens:
|
|
294
|
+
token_count = 0
|
|
295
|
+
filtered = []
|
|
296
|
+
# Collect messages from newest to oldest until we hit the limit
|
|
297
|
+
for msg in reversed(history):
|
|
298
|
+
msg_tokens = self.get_message_tokens(msg)
|
|
299
|
+
if token_count + msg_tokens > self._config.max_tokens:
|
|
300
|
+
break
|
|
301
|
+
token_count += msg_tokens
|
|
302
|
+
filtered.append(msg)
|
|
303
|
+
history = list(reversed(filtered))
|
|
304
|
+
|
|
305
|
+
return list(history)
|
|
306
|
+
|
|
307
|
+
def get_pending_parts(self) -> list[UserContent]:
|
|
308
|
+
"""Get and clear pending content parts for the next interaction.
|
|
309
|
+
|
|
310
|
+
Returns:
|
|
311
|
+
List of pending UserContent parts, clearing the internal queue.
|
|
312
|
+
"""
|
|
313
|
+
parts = list(self._pending_parts)
|
|
314
|
+
self._pending_parts.clear()
|
|
315
|
+
return parts
|
|
316
|
+
|
|
317
|
+
def clear_pending(self) -> None:
|
|
318
|
+
"""Clear pending parts without using them."""
|
|
319
|
+
self._pending_parts.clear()
|
|
320
|
+
|
|
321
|
+
def set_history(self, history: list[ChatMessage[Any]]) -> None:
|
|
322
|
+
"""Update conversation history after run."""
|
|
323
|
+
self.chat_messages.clear()
|
|
324
|
+
self.chat_messages.extend(history)
|
|
325
|
+
|
|
326
|
+
def clear(self) -> None:
|
|
327
|
+
"""Clear conversation history and prompts."""
|
|
328
|
+
from agentpool.messaging import ChatMessageList
|
|
329
|
+
|
|
330
|
+
self.chat_messages = ChatMessageList()
|
|
331
|
+
self._last_messages = []
|
|
332
|
+
event = self.HistoryCleared(session_id=str(self.id))
|
|
333
|
+
self.history_cleared.emit(event)
|
|
334
|
+
|
|
335
|
+
@asynccontextmanager
|
|
336
|
+
async def temporary_state(
|
|
337
|
+
self,
|
|
338
|
+
history: list[AnyPromptType] | SessionQuery | None = None,
|
|
339
|
+
*,
|
|
340
|
+
replace_history: bool = False,
|
|
341
|
+
) -> AsyncIterator[Self]:
|
|
342
|
+
"""Temporarily set conversation history.
|
|
343
|
+
|
|
344
|
+
Args:
|
|
345
|
+
history: Optional list of prompts to use as temporary history.
|
|
346
|
+
Can be strings, BasePrompts, or other prompt types.
|
|
347
|
+
replace_history: If True, only use provided history. If False, append
|
|
348
|
+
to existing history.
|
|
349
|
+
"""
|
|
350
|
+
from toprompt import to_prompt
|
|
351
|
+
|
|
352
|
+
from agentpool.messaging import ChatMessage, ChatMessageList
|
|
353
|
+
|
|
354
|
+
old_history = self.chat_messages.copy()
|
|
355
|
+
try:
|
|
356
|
+
messages: Sequence[ChatMessage[Any]] = ChatMessageList()
|
|
357
|
+
if history is not None:
|
|
358
|
+
if isinstance(history, SessionQuery):
|
|
359
|
+
messages = await self.storage.filter_messages(history)
|
|
360
|
+
else:
|
|
361
|
+
messages = [
|
|
362
|
+
ChatMessage.user_prompt(message=prompt)
|
|
363
|
+
for p in history
|
|
364
|
+
if (prompt := await to_prompt(p))
|
|
365
|
+
]
|
|
366
|
+
|
|
367
|
+
if replace_history:
|
|
368
|
+
self.chat_messages = ChatMessageList(messages)
|
|
369
|
+
else:
|
|
370
|
+
self.chat_messages.extend(messages)
|
|
371
|
+
|
|
372
|
+
yield self
|
|
373
|
+
|
|
374
|
+
finally:
|
|
375
|
+
self.chat_messages = old_history
|
|
376
|
+
|
|
377
|
+
def add_chat_messages(self, messages: Sequence[ChatMessage[Any]]) -> None:
|
|
378
|
+
"""Add new messages to history and update last_messages."""
|
|
379
|
+
self._last_messages = list(messages)
|
|
380
|
+
self.chat_messages.extend(messages)
|
|
381
|
+
|
|
382
|
+
@property
|
|
383
|
+
def last_run_messages(self) -> list[ChatMessage[Any]]:
|
|
384
|
+
"""Get messages from the last run converted to our format."""
|
|
385
|
+
return self._last_messages
|
|
386
|
+
|
|
387
|
+
def add_context_part(
|
|
388
|
+
self,
|
|
389
|
+
content: UserContent,
|
|
390
|
+
) -> None:
|
|
391
|
+
"""Add a content part to be included in the next request.
|
|
392
|
+
|
|
393
|
+
Args:
|
|
394
|
+
content: UserContent part (str, ImageUrl, BinaryContent, etc.)
|
|
395
|
+
"""
|
|
396
|
+
self._pending_parts.append(content)
|
|
397
|
+
|
|
398
|
+
def add_context_message(
|
|
399
|
+
self,
|
|
400
|
+
content: str,
|
|
401
|
+
source: str | None = None,
|
|
402
|
+
**metadata: Any,
|
|
403
|
+
) -> None:
|
|
404
|
+
"""Add a text context message.
|
|
405
|
+
|
|
406
|
+
Args:
|
|
407
|
+
content: Text content to add
|
|
408
|
+
source: Description of content source
|
|
409
|
+
**metadata: Additional metadata to include with the message
|
|
410
|
+
"""
|
|
411
|
+
meta_str = ""
|
|
412
|
+
if metadata:
|
|
413
|
+
meta_str = "\n".join(f"{k}: {v}" for k, v in metadata.items())
|
|
414
|
+
meta_str = f"\nMetadata:\n{meta_str}\n"
|
|
415
|
+
|
|
416
|
+
header = f"Content from {source}:" if source else "Additional context:"
|
|
417
|
+
formatted = f"{header}{meta_str}\n{content}\n"
|
|
418
|
+
self._pending_parts.append(formatted)
|
|
419
|
+
|
|
420
|
+
async def add_context_from_path(
|
|
421
|
+
self,
|
|
422
|
+
path: JoinablePathLike,
|
|
423
|
+
*,
|
|
424
|
+
convert_to_md: bool = False,
|
|
425
|
+
**metadata: Any,
|
|
426
|
+
) -> None:
|
|
427
|
+
"""Add file or URL content as context message.
|
|
428
|
+
|
|
429
|
+
Args:
|
|
430
|
+
path: Any UPath-supported path
|
|
431
|
+
convert_to_md: Whether to convert content to markdown
|
|
432
|
+
**metadata: Additional metadata to include with the message
|
|
433
|
+
|
|
434
|
+
Raises:
|
|
435
|
+
ValueError: If content cannot be loaded or converted
|
|
436
|
+
"""
|
|
437
|
+
path_obj = to_upath(path)
|
|
438
|
+
if convert_to_md:
|
|
439
|
+
content = await self._converter.convert_file(path)
|
|
440
|
+
source = f"markdown:{path_obj.name}"
|
|
441
|
+
else:
|
|
442
|
+
content = await read_path(path)
|
|
443
|
+
source = f"{path_obj.protocol}:{path_obj.name}"
|
|
444
|
+
self.add_context_message(content, source=source, **metadata)
|
|
445
|
+
|
|
446
|
+
async def add_context_from_prompt(
|
|
447
|
+
self,
|
|
448
|
+
prompt: PromptType,
|
|
449
|
+
metadata: dict[str, Any] | None = None,
|
|
450
|
+
**kwargs: Any,
|
|
451
|
+
) -> None:
|
|
452
|
+
"""Add rendered prompt content as context message.
|
|
453
|
+
|
|
454
|
+
Args:
|
|
455
|
+
prompt: AgentPool prompt (static, dynamic, or file-based)
|
|
456
|
+
metadata: Additional metadata to include with the message
|
|
457
|
+
kwargs: Optional kwargs for prompt formatting
|
|
458
|
+
"""
|
|
459
|
+
try:
|
|
460
|
+
# Format the prompt using AgentPool's prompt system
|
|
461
|
+
messages = await prompt.format(kwargs)
|
|
462
|
+
# Extract text content from all messages
|
|
463
|
+
content = "\n\n".join(msg.get_text_content() for msg in messages)
|
|
464
|
+
|
|
465
|
+
self.add_context_message(
|
|
466
|
+
content,
|
|
467
|
+
source=f"prompt:{prompt.name or prompt.type}",
|
|
468
|
+
prompt_args=kwargs,
|
|
469
|
+
**(metadata or {}),
|
|
470
|
+
)
|
|
471
|
+
except Exception as e:
|
|
472
|
+
msg = f"Failed to format prompt: {e}"
|
|
473
|
+
raise ValueError(msg) from e
|
|
474
|
+
|
|
475
|
+
def get_history_tokens(self) -> int:
|
|
476
|
+
"""Get token count for current history."""
|
|
477
|
+
# Use cost_info if available
|
|
478
|
+
return self.chat_messages.get_history_tokens()
|
|
479
|
+
|
|
480
|
+
|
|
481
|
+
if __name__ == "__main__":
|
|
482
|
+
from agentpool import Agent
|
|
483
|
+
|
|
484
|
+
async def main() -> None:
|
|
485
|
+
async with Agent() as agent:
|
|
486
|
+
await agent.conversation.add_context_from_path("E:/mcp_zed.yml")
|
|
487
|
+
print(agent.conversation.get_history())
|
|
488
|
+
|
|
489
|
+
import anyio
|
|
490
|
+
|
|
491
|
+
anyio.run(main)
|