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,334 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import asyncio
|
|
4
|
+
from collections.abc import Sequence
|
|
5
|
+
from dataclasses import fields
|
|
6
|
+
import functools
|
|
7
|
+
from importlib.util import find_spec
|
|
8
|
+
import inspect
|
|
9
|
+
from types import UnionType
|
|
10
|
+
from typing import (
|
|
11
|
+
TYPE_CHECKING,
|
|
12
|
+
Any,
|
|
13
|
+
Literal,
|
|
14
|
+
TypeAliasType,
|
|
15
|
+
TypeGuard,
|
|
16
|
+
Union,
|
|
17
|
+
get_args,
|
|
18
|
+
get_origin,
|
|
19
|
+
get_type_hints,
|
|
20
|
+
overload,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
if TYPE_CHECKING:
|
|
25
|
+
from collections.abc import Awaitable, Callable
|
|
26
|
+
|
|
27
|
+
from agentpool.agents import AgentContext
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
PACKAGE_NAME = "agentpool"
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def dataclasses_no_defaults_repr(self: Any) -> str:
|
|
34
|
+
"""Exclude fields with values equal to the field default."""
|
|
35
|
+
kv_pairs = (
|
|
36
|
+
f"{f.name}={getattr(self, f.name)!r}"
|
|
37
|
+
for f in fields(self)
|
|
38
|
+
if f.repr and getattr(self, f.name) != f.default
|
|
39
|
+
)
|
|
40
|
+
return f"{self.__class__.__qualname__}({', '.join(kv_pairs)})"
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
@overload
|
|
44
|
+
async def execute[T](
|
|
45
|
+
func: Callable[..., Awaitable[T]],
|
|
46
|
+
*args: Any,
|
|
47
|
+
use_thread: bool = False,
|
|
48
|
+
**kwargs: Any,
|
|
49
|
+
) -> T: ...
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
@overload
|
|
53
|
+
async def execute[T](
|
|
54
|
+
func: Callable[..., T | Awaitable[T]],
|
|
55
|
+
*args: Any,
|
|
56
|
+
use_thread: bool = False,
|
|
57
|
+
**kwargs: Any,
|
|
58
|
+
) -> T: ...
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
async def execute[T](
|
|
62
|
+
func: Callable[..., T | Awaitable[T]],
|
|
63
|
+
*args: Any,
|
|
64
|
+
use_thread: bool = False,
|
|
65
|
+
**kwargs: Any,
|
|
66
|
+
) -> T:
|
|
67
|
+
"""Execute callable, handling both sync and async cases."""
|
|
68
|
+
if inspect.iscoroutinefunction(func):
|
|
69
|
+
return await func(*args, **kwargs) # type: ignore[no-any-return]
|
|
70
|
+
|
|
71
|
+
if use_thread:
|
|
72
|
+
result = await asyncio.to_thread(func, *args, **kwargs)
|
|
73
|
+
else:
|
|
74
|
+
result = func(*args, **kwargs)
|
|
75
|
+
|
|
76
|
+
if inspect.iscoroutine(result) or inspect.isawaitable(result):
|
|
77
|
+
return await result # ty: ignore
|
|
78
|
+
|
|
79
|
+
return result
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def get_argument_key(
|
|
83
|
+
func: Callable[..., Any],
|
|
84
|
+
arg_type: type | str | UnionType | Sequence[type | str | UnionType],
|
|
85
|
+
include_return: bool = False,
|
|
86
|
+
) -> Literal[False] | str:
|
|
87
|
+
"""Check if function has any argument of specified type(s) and return the key.
|
|
88
|
+
|
|
89
|
+
Args:
|
|
90
|
+
func: Function to check
|
|
91
|
+
arg_type: Type(s) to look for. Can be:
|
|
92
|
+
- Single type (int, str, etc)
|
|
93
|
+
- Union type (int | str)
|
|
94
|
+
- Type name as string
|
|
95
|
+
- Sequence of the above
|
|
96
|
+
include_return: Whether to also check return type annotation
|
|
97
|
+
|
|
98
|
+
Examples:
|
|
99
|
+
>>> def func(x: int | str, y: list[int]): ...
|
|
100
|
+
>>> get_argument_key(func, int | str) # Returns 'x'
|
|
101
|
+
>>> get_argument_key(func, int) # Returns 'x'
|
|
102
|
+
>>> get_argument_key(func, list) # Returns 'y'
|
|
103
|
+
>>> get_argument_key(func, float) # Returns False
|
|
104
|
+
>>> get_argument_key(func, (int, str)) # Returns 'x'
|
|
105
|
+
|
|
106
|
+
Returns:
|
|
107
|
+
Parameter name (str) if a matching argument is found, False otherwise.
|
|
108
|
+
Only checks the origin type for generics, not type arguments
|
|
109
|
+
(e.g., list[int] matches 'list', but does not match 'int').
|
|
110
|
+
"""
|
|
111
|
+
# Convert target type(s) to set of normalized strings
|
|
112
|
+
if isinstance(arg_type, Sequence) and not isinstance(arg_type, str | bytes):
|
|
113
|
+
target_types = {_type_to_string(t) for t in arg_type}
|
|
114
|
+
else:
|
|
115
|
+
target_types = {_type_to_string(arg_type)}
|
|
116
|
+
|
|
117
|
+
# Get type hints including return type if requested
|
|
118
|
+
hints = get_type_hints(func, include_extras=True)
|
|
119
|
+
if not include_return:
|
|
120
|
+
hints.pop("return", None)
|
|
121
|
+
|
|
122
|
+
# Check each parameter's type annotation
|
|
123
|
+
for key, param_type_ in hints.items():
|
|
124
|
+
# Handle type aliases
|
|
125
|
+
param_type = (
|
|
126
|
+
param_type_.__value__ if isinstance(param_type_, TypeAliasType) else param_type_
|
|
127
|
+
)
|
|
128
|
+
# Check for direct match
|
|
129
|
+
if _type_to_string(param_type) in target_types:
|
|
130
|
+
return key
|
|
131
|
+
|
|
132
|
+
# Handle Union types (both | and Union[...])
|
|
133
|
+
origin = get_origin(param_type)
|
|
134
|
+
if origin is Union or origin is UnionType:
|
|
135
|
+
union_members = get_args(param_type)
|
|
136
|
+
# Check each union member
|
|
137
|
+
if any(_type_to_string(t) in target_types for t in union_members):
|
|
138
|
+
return key
|
|
139
|
+
# Also check if the complete union type matches
|
|
140
|
+
if _type_to_string(param_type) in target_types:
|
|
141
|
+
return key
|
|
142
|
+
|
|
143
|
+
# Handle generic types (list[str], dict[str, int], etc)
|
|
144
|
+
# Only check the origin type (e.g., list), not the arguments
|
|
145
|
+
# This avoids matching nested contexts like RunContext[AgentContext]
|
|
146
|
+
if origin is not None and _type_to_string(origin) in target_types:
|
|
147
|
+
return key
|
|
148
|
+
|
|
149
|
+
# if origin is not None:
|
|
150
|
+
# # Check if the generic type (e.g., list) matches
|
|
151
|
+
# if _type_to_string(origin) in target_types:
|
|
152
|
+
# return key
|
|
153
|
+
# # Check type arguments (e.g., str in list[str])
|
|
154
|
+
# args = get_args(param_type)
|
|
155
|
+
# if any(_type_to_string(arg) in target_types for arg in args):
|
|
156
|
+
# return key
|
|
157
|
+
|
|
158
|
+
return False
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
def is_async_callable(obj: Any) -> Any:
|
|
162
|
+
"""Correctly check if a callable is async.
|
|
163
|
+
|
|
164
|
+
This function was copied from Starlette:
|
|
165
|
+
https://github.com/encode/starlette/blob/78da9b9e218ab289117df7d62aee200ed4c59617/starlette/_utils.py#L36-L40
|
|
166
|
+
"""
|
|
167
|
+
while isinstance(obj, functools.partial):
|
|
168
|
+
obj = obj.func
|
|
169
|
+
|
|
170
|
+
return inspect.iscoroutinefunction(obj) or (
|
|
171
|
+
callable(obj) and inspect.iscoroutinefunction(obj.__call__)
|
|
172
|
+
)
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def _type_to_string(type_hint: Any) -> str:
|
|
176
|
+
"""Convert type to normalized string representation for comparison."""
|
|
177
|
+
match type_hint:
|
|
178
|
+
case str():
|
|
179
|
+
return type_hint
|
|
180
|
+
case type():
|
|
181
|
+
return type_hint.__name__
|
|
182
|
+
case TypeAliasType():
|
|
183
|
+
return _type_to_string(type_hint.__value__)
|
|
184
|
+
case UnionType():
|
|
185
|
+
args = get_args(type_hint)
|
|
186
|
+
args_str = ", ".join(_type_to_string(t) for t in args)
|
|
187
|
+
return f"Union[{args_str}]"
|
|
188
|
+
case _:
|
|
189
|
+
return str(type_hint)
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
def has_return_type[T]( # noqa: PLR0911
|
|
193
|
+
func: Callable[..., Any],
|
|
194
|
+
expected_type: type[T],
|
|
195
|
+
) -> TypeGuard[Callable[..., T | Awaitable[T]]]:
|
|
196
|
+
"""Check if a function has a specific return type annotation.
|
|
197
|
+
|
|
198
|
+
Args:
|
|
199
|
+
func: Function to check
|
|
200
|
+
expected_type: The type to check for
|
|
201
|
+
|
|
202
|
+
Returns:
|
|
203
|
+
True if function returns the expected type (or Awaitable of it)
|
|
204
|
+
"""
|
|
205
|
+
hints = get_type_hints(func)
|
|
206
|
+
if "return" not in hints:
|
|
207
|
+
return False
|
|
208
|
+
|
|
209
|
+
return_type = hints["return"]
|
|
210
|
+
|
|
211
|
+
# Handle direct match
|
|
212
|
+
if return_type is expected_type:
|
|
213
|
+
return True
|
|
214
|
+
|
|
215
|
+
# Handle TypeAliases
|
|
216
|
+
if isinstance(return_type, TypeAliasType):
|
|
217
|
+
return_type = return_type.__value__
|
|
218
|
+
|
|
219
|
+
# Handle Union types (including Optional)
|
|
220
|
+
origin = get_origin(return_type)
|
|
221
|
+
args = get_args(return_type)
|
|
222
|
+
|
|
223
|
+
if origin is Union or origin is UnionType:
|
|
224
|
+
# Check each union member
|
|
225
|
+
def check_type(t: Any) -> bool:
|
|
226
|
+
return has_return_type(lambda: t, expected_type)
|
|
227
|
+
|
|
228
|
+
return any(check_type(arg) for arg in args)
|
|
229
|
+
|
|
230
|
+
# Handle Awaitable/Coroutine types
|
|
231
|
+
if origin is not None and inspect.iscoroutinefunction(func):
|
|
232
|
+
# For async functions, check the first type argument
|
|
233
|
+
if args:
|
|
234
|
+
# Recursively check the awaited type
|
|
235
|
+
return has_return_type(lambda: args[0], expected_type)
|
|
236
|
+
return False
|
|
237
|
+
|
|
238
|
+
# Handle generic types (like list[str], etc)
|
|
239
|
+
if origin is not None:
|
|
240
|
+
return origin is expected_type
|
|
241
|
+
|
|
242
|
+
return False
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
def call_with_context[T](
|
|
246
|
+
func: Callable[..., T],
|
|
247
|
+
context: AgentContext[Any],
|
|
248
|
+
**kwargs: Any,
|
|
249
|
+
) -> T:
|
|
250
|
+
"""Call function with appropriate context injection.
|
|
251
|
+
|
|
252
|
+
Handles:
|
|
253
|
+
- Simple functions
|
|
254
|
+
- Bound methods
|
|
255
|
+
- Functions expecting AgentContext
|
|
256
|
+
- Functions expecting context data
|
|
257
|
+
"""
|
|
258
|
+
from agentpool.agents import AgentContext
|
|
259
|
+
|
|
260
|
+
if inspect.ismethod(func):
|
|
261
|
+
if get_argument_key(func, AgentContext):
|
|
262
|
+
return func(context) # type: ignore[no-any-return]
|
|
263
|
+
return func() # type: ignore[no-any-return]
|
|
264
|
+
if get_argument_key(func, AgentContext):
|
|
265
|
+
return func(context, **kwargs)
|
|
266
|
+
return func(context.data)
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
def validate_import(module_path: str, extras_name: str) -> None:
|
|
270
|
+
"""Check existence of module, showing helpful error if not installed."""
|
|
271
|
+
if not find_spec(module_path):
|
|
272
|
+
msg = f"""
|
|
273
|
+
Optional dependency {module_path!r} not found.
|
|
274
|
+
Install with: pip install {PACKAGE_NAME}[{extras_name}]
|
|
275
|
+
"""
|
|
276
|
+
raise ImportError(msg.strip())
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
def get_fn_name(func: Any) -> str:
|
|
280
|
+
"""Get the __name__ of a callable, handling edge cases.
|
|
281
|
+
|
|
282
|
+
Works with regular functions, lambdas, partials, and other callables
|
|
283
|
+
that may not have a __name__ attribute.
|
|
284
|
+
|
|
285
|
+
Args:
|
|
286
|
+
func: Any callable object
|
|
287
|
+
|
|
288
|
+
Returns:
|
|
289
|
+
The function name, or a fallback string if not available
|
|
290
|
+
"""
|
|
291
|
+
# Unwrap functools.partial
|
|
292
|
+
while isinstance(func, functools.partial):
|
|
293
|
+
func = func.func
|
|
294
|
+
|
|
295
|
+
# Try __name__ first (most common case)
|
|
296
|
+
if hasattr(func, "__name__"):
|
|
297
|
+
return func.__name__ # type: ignore[no-any-return]
|
|
298
|
+
|
|
299
|
+
# Try __class__.__name__ for callable objects
|
|
300
|
+
if hasattr(func, "__class__"):
|
|
301
|
+
return func.__class__.__name__ # type: ignore[no-any-return]
|
|
302
|
+
|
|
303
|
+
return "<unknown>"
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
def get_fn_qualname(func: Any) -> str:
|
|
307
|
+
"""Get the __qualname__ of a callable, handling edge cases.
|
|
308
|
+
|
|
309
|
+
Works with regular functions, lambdas, partials, methods, and other
|
|
310
|
+
callables that may not have a __qualname__ attribute.
|
|
311
|
+
|
|
312
|
+
Args:
|
|
313
|
+
func: Any callable object
|
|
314
|
+
|
|
315
|
+
Returns:
|
|
316
|
+
The qualified name, or a fallback string if not available
|
|
317
|
+
"""
|
|
318
|
+
# Unwrap functools.partial
|
|
319
|
+
while isinstance(func, functools.partial):
|
|
320
|
+
func = func.func
|
|
321
|
+
|
|
322
|
+
# Try __qualname__ first (most common case)
|
|
323
|
+
if hasattr(func, "__qualname__"):
|
|
324
|
+
return func.__qualname__ # type: ignore[no-any-return]
|
|
325
|
+
|
|
326
|
+
# Fall back to __name__
|
|
327
|
+
if hasattr(func, "__name__"):
|
|
328
|
+
return func.__name__ # type: ignore[no-any-return]
|
|
329
|
+
|
|
330
|
+
# Try __class__.__qualname__ for callable objects
|
|
331
|
+
if hasattr(func, "__class__"):
|
|
332
|
+
return func.__class__.__qualname__ # type: ignore[no-any-return]
|
|
333
|
+
|
|
334
|
+
return "<unknown>"
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"""Model capability utilities."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
async def supports_vision(model_name: str | None) -> bool:
|
|
7
|
+
"""Check if a model supports vision capabilities.
|
|
8
|
+
|
|
9
|
+
Args:
|
|
10
|
+
model_name: Name of the model to check
|
|
11
|
+
|
|
12
|
+
Returns:
|
|
13
|
+
True if the model supports vision, False otherwise
|
|
14
|
+
"""
|
|
15
|
+
if not model_name:
|
|
16
|
+
return False
|
|
17
|
+
|
|
18
|
+
try:
|
|
19
|
+
import tokonomics
|
|
20
|
+
|
|
21
|
+
caps = await tokonomics.get_model_capabilities(model_name)
|
|
22
|
+
return bool(caps and caps.supports_vision)
|
|
23
|
+
except ImportError:
|
|
24
|
+
# If tokonomics is not available, return False
|
|
25
|
+
return False
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import TYPE_CHECKING
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
if TYPE_CHECKING:
|
|
7
|
+
import socket
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def _create_socket(preferred_port: int) -> tuple[socket.socket, int]:
|
|
11
|
+
"""Create a socket bound to a free port.
|
|
12
|
+
|
|
13
|
+
Returns:
|
|
14
|
+
A tuple containing the socket and the port it is bound to.
|
|
15
|
+
"""
|
|
16
|
+
import socket
|
|
17
|
+
|
|
18
|
+
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
19
|
+
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
|
20
|
+
try:
|
|
21
|
+
# Try preferred port first
|
|
22
|
+
sock.bind(("127.0.0.1", preferred_port))
|
|
23
|
+
except OSError:
|
|
24
|
+
# Fall back to any available port
|
|
25
|
+
sock.bind(("127.0.0.1", 0))
|
|
26
|
+
return sock, sock.getsockname()[1]
|
|
27
|
+
else:
|
|
28
|
+
return sock, preferred_port
|
agentpool/utils/now.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"""Date and time utilities."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from datetime import UTC, datetime
|
|
6
|
+
from typing import Literal
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
TimeZoneMode = Literal["utc", "local"]
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def get_now(tz_mode: TimeZoneMode = "utc") -> datetime:
|
|
13
|
+
"""Get current datetime in UTC or local timezone.
|
|
14
|
+
|
|
15
|
+
Args:
|
|
16
|
+
tz_mode: "utc" or "local" (default: "utc")
|
|
17
|
+
|
|
18
|
+
Returns:
|
|
19
|
+
Timezone-aware datetime object
|
|
20
|
+
"""
|
|
21
|
+
now = datetime.now(UTC)
|
|
22
|
+
return now.astimezone() if tz_mode == "local" else now
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"""Time period parsing for CLI and API interfaces."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from datetime import timedelta
|
|
6
|
+
import re
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
# Time units with their patterns
|
|
10
|
+
_WEEKS = r"(?P<weeks>[\d.]+)\s*(?:w|wks?|weeks?)"
|
|
11
|
+
_DAYS = r"(?P<days>[\d.]+)\s*(?:d|dys?|days?)"
|
|
12
|
+
_HOURS = r"(?P<hours>[\d.]+)\s*(?:h|hrs?|hours?)"
|
|
13
|
+
_MINS = r"(?P<mins>[\d.]+)\s*(?:m|mins?|minutes?)"
|
|
14
|
+
_SECS = r"(?P<secs>[\d.]+)\s*(?:s|secs?|seconds?)"
|
|
15
|
+
|
|
16
|
+
# Separators between units
|
|
17
|
+
_SEPARATORS = r"[,/]"
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
# Optional patterns with separators
|
|
21
|
+
def _OPT(x: str) -> str: # noqa: N802
|
|
22
|
+
return f"(?:{x})?"
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _OPTSEP(x: str) -> str: # noqa: N802
|
|
26
|
+
return f"(?:{x}\\s*(?:{_SEPARATORS}\\s*)?)?"
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
# All supported time formats
|
|
30
|
+
_TIME_FORMAT = f"{_OPTSEP(_WEEKS)}{_OPTSEP(_DAYS)}{_OPTSEP(_HOURS)}{_OPTSEP(_MINS)}{_OPT(_SECS)}"
|
|
31
|
+
|
|
32
|
+
# Time unit multipliers in seconds
|
|
33
|
+
_MULTIPLIERS = {
|
|
34
|
+
"weeks": 60 * 60 * 24 * 7,
|
|
35
|
+
"days": 60 * 60 * 24,
|
|
36
|
+
"hours": 60 * 60,
|
|
37
|
+
"mins": 60,
|
|
38
|
+
"secs": 1,
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
# Compile patterns
|
|
42
|
+
_SIGN_PATTERN = re.compile(r"\s*(?P<sign>[+|-])?\s*(?P<unsigned>.*$)")
|
|
43
|
+
_TIME_PATTERN = re.compile(rf"\s*{_TIME_FORMAT}\s*$", re.IGNORECASE)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def parse_time_period(period: str) -> timedelta:
|
|
47
|
+
"""Parse a time expression into a timedelta.
|
|
48
|
+
|
|
49
|
+
Examples:
|
|
50
|
+
- Simple format: 1h, 2d, 1w
|
|
51
|
+
- Full words: 1 hour, 2 days, 1 week
|
|
52
|
+
- Combined: 1 week 2 days 3 hours
|
|
53
|
+
- With separators: 1h, 30m
|
|
54
|
+
- Signed: -1h, +2d
|
|
55
|
+
- Decimal values: 1.5h
|
|
56
|
+
|
|
57
|
+
Args:
|
|
58
|
+
period: Time period string to parse
|
|
59
|
+
|
|
60
|
+
Raises:
|
|
61
|
+
ValueError: If the time format is invalid
|
|
62
|
+
|
|
63
|
+
Returns:
|
|
64
|
+
Parsed time period as timedelta
|
|
65
|
+
"""
|
|
66
|
+
# Handle sign
|
|
67
|
+
sign_match = _SIGN_PATTERN.match(period)
|
|
68
|
+
if not sign_match:
|
|
69
|
+
msg = f"Invalid time format: {period}"
|
|
70
|
+
raise ValueError(msg)
|
|
71
|
+
|
|
72
|
+
sign = -1 if sign_match.group("sign") == "-" else 1
|
|
73
|
+
unsigned = sign_match.group("unsigned")
|
|
74
|
+
|
|
75
|
+
# Match time pattern
|
|
76
|
+
if match := _TIME_PATTERN.match(unsigned):
|
|
77
|
+
dct = match.groupdict()
|
|
78
|
+
matches = {k: v for k, v in dct.items() if v is not None}
|
|
79
|
+
try:
|
|
80
|
+
secs = sum(_MULTIPLIERS[unit] * float(val) for unit, val in matches.items())
|
|
81
|
+
return timedelta(seconds=sign * secs)
|
|
82
|
+
except (ValueError, KeyError) as e:
|
|
83
|
+
msg = f"Invalid time value in: {period}"
|
|
84
|
+
raise ValueError(msg) from e
|
|
85
|
+
|
|
86
|
+
msg = f"Unsupported time format: {period}"
|
|
87
|
+
raise ValueError(msg)
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"""Response utilities."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import TYPE_CHECKING, Any
|
|
6
|
+
|
|
7
|
+
from pydantic import BaseModel
|
|
8
|
+
from schemez import InlineSchemaDef
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
if TYPE_CHECKING:
|
|
12
|
+
from agentpool_config.output_types import StructuredResponseConfig
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def to_type(
|
|
16
|
+
output_type: Any,
|
|
17
|
+
# output_type: str | InlineSchemaDef | type | None,
|
|
18
|
+
responses: dict[str, StructuredResponseConfig] | None = None,
|
|
19
|
+
) -> type[BaseModel | str]:
|
|
20
|
+
match output_type:
|
|
21
|
+
case str() if responses and output_type in responses:
|
|
22
|
+
defn = responses[output_type] # from defined responses
|
|
23
|
+
return defn.response_schema.get_schema()
|
|
24
|
+
case str():
|
|
25
|
+
msg = f"Missing responses dict for response type: {output_type!r}"
|
|
26
|
+
raise ValueError(msg)
|
|
27
|
+
case InlineSchemaDef():
|
|
28
|
+
return output_type.get_schema()
|
|
29
|
+
case None:
|
|
30
|
+
return str
|
|
31
|
+
case type() as model if issubclass(model, BaseModel | str):
|
|
32
|
+
return model
|
|
33
|
+
case _:
|
|
34
|
+
msg = f"Invalid output_type: {type(output_type)}"
|
|
35
|
+
raise TypeError(msg)
|