autobyteus 1.0.6__py3-none-any.whl → 1.1.1__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.
- autobyteus/agent/agent.py +97 -222
- autobyteus/agent/bootstrap_steps/__init__.py +19 -0
- autobyteus/agent/bootstrap_steps/agent_bootstrapper.py +88 -0
- autobyteus/agent/bootstrap_steps/agent_runtime_queue_initialization_step.py +57 -0
- autobyteus/agent/bootstrap_steps/base_bootstrap_step.py +38 -0
- autobyteus/agent/bootstrap_steps/system_prompt_processing_step.py +93 -0
- autobyteus/agent/bootstrap_steps/workspace_context_initialization_step.py +47 -0
- autobyteus/agent/context/__init__.py +13 -0
- autobyteus/agent/context/agent_config.py +84 -0
- autobyteus/agent/context/agent_context.py +129 -0
- autobyteus/agent/context/agent_phase_manager.py +264 -0
- autobyteus/agent/context/agent_runtime_state.py +89 -0
- autobyteus/agent/context/phases.py +49 -0
- autobyteus/agent/events/__init__.py +52 -0
- autobyteus/agent/events/agent_events.py +110 -0
- autobyteus/agent/events/agent_input_event_queue_manager.py +174 -0
- autobyteus/agent/events/notifiers.py +122 -0
- autobyteus/agent/events/worker_event_dispatcher.py +118 -0
- autobyteus/agent/factory/__init__.py +9 -0
- autobyteus/agent/factory/agent_factory.py +145 -0
- autobyteus/agent/group/agent_group.py +164 -0
- autobyteus/agent/group/agent_group_context.py +81 -0
- autobyteus/agent/handlers/__init__.py +36 -0
- autobyteus/agent/handlers/approved_tool_invocation_event_handler.py +148 -0
- autobyteus/agent/handlers/base_event_handler.py +36 -0
- autobyteus/agent/handlers/event_handler_registry.py +76 -0
- autobyteus/agent/handlers/generic_event_handler.py +46 -0
- autobyteus/agent/handlers/inter_agent_message_event_handler.py +76 -0
- autobyteus/agent/handlers/lifecycle_event_logger.py +64 -0
- autobyteus/agent/handlers/llm_complete_response_received_event_handler.py +138 -0
- autobyteus/agent/handlers/llm_user_message_ready_event_handler.py +140 -0
- autobyteus/agent/handlers/tool_execution_approval_event_handler.py +85 -0
- autobyteus/agent/handlers/tool_invocation_request_event_handler.py +211 -0
- autobyteus/agent/handlers/tool_result_event_handler.py +101 -0
- autobyteus/agent/handlers/user_input_message_event_handler.py +77 -0
- autobyteus/agent/hooks/__init__.py +16 -0
- autobyteus/agent/hooks/base_phase_hook.py +61 -0
- autobyteus/agent/hooks/hook_definition.py +36 -0
- autobyteus/agent/hooks/hook_meta.py +37 -0
- autobyteus/agent/hooks/hook_registry.py +118 -0
- autobyteus/agent/input_processor/__init__.py +18 -0
- autobyteus/agent/input_processor/base_user_input_processor.py +54 -0
- autobyteus/agent/input_processor/content_prefixing_input_processor.py +41 -0
- autobyteus/agent/input_processor/metadata_appending_input_processor.py +34 -0
- autobyteus/agent/input_processor/passthrough_input_processor.py +33 -0
- autobyteus/agent/input_processor/processor_definition.py +42 -0
- autobyteus/agent/input_processor/processor_meta.py +46 -0
- autobyteus/agent/input_processor/processor_registry.py +117 -0
- autobyteus/agent/llm_response_processor/__init__.py +16 -0
- autobyteus/agent/llm_response_processor/base_processor.py +53 -0
- autobyteus/agent/llm_response_processor/processor_definition.py +36 -0
- autobyteus/agent/llm_response_processor/processor_meta.py +37 -0
- autobyteus/agent/llm_response_processor/processor_registry.py +113 -0
- autobyteus/agent/llm_response_processor/provider_aware_tool_usage_processor.py +54 -0
- autobyteus/agent/message/__init__.py +20 -0
- autobyteus/agent/message/agent_input_user_message.py +96 -0
- autobyteus/agent/message/context_file.py +82 -0
- autobyteus/agent/message/context_file_type.py +63 -0
- autobyteus/agent/message/{message.py → inter_agent_message.py} +12 -12
- autobyteus/agent/message/{message_types.py → inter_agent_message_type.py} +8 -6
- autobyteus/agent/message/send_message_to.py +142 -36
- autobyteus/agent/phases/__init__.py +18 -0
- autobyteus/agent/phases/discover.py +52 -0
- autobyteus/agent/phases/manager.py +265 -0
- autobyteus/agent/phases/phase_enum.py +49 -0
- autobyteus/agent/phases/transition_decorator.py +40 -0
- autobyteus/agent/phases/transition_info.py +33 -0
- autobyteus/agent/remote_agent.py +244 -0
- autobyteus/agent/runtime/__init__.py +15 -0
- autobyteus/agent/runtime/agent_runtime.py +137 -0
- autobyteus/agent/runtime/agent_thread_pool_manager.py +88 -0
- autobyteus/agent/runtime/agent_worker.py +200 -0
- autobyteus/agent/streaming/__init__.py +15 -0
- autobyteus/agent/streaming/agent_event_stream.py +173 -0
- autobyteus/agent/streaming/queue_streamer.py +58 -0
- autobyteus/agent/streaming/stream_event_payloads.py +167 -0
- autobyteus/agent/streaming/stream_events.py +126 -0
- autobyteus/agent/system_prompt_processor/__init__.py +14 -0
- autobyteus/agent/system_prompt_processor/base_processor.py +48 -0
- autobyteus/agent/system_prompt_processor/processor_definition.py +40 -0
- autobyteus/agent/system_prompt_processor/processor_meta.py +47 -0
- autobyteus/agent/system_prompt_processor/processor_registry.py +119 -0
- autobyteus/agent/system_prompt_processor/tool_manifest_injector_processor.py +79 -0
- autobyteus/agent/tool_invocation.py +54 -5
- autobyteus/agent/utils/__init__.py +9 -0
- autobyteus/agent/utils/wait_for_idle.py +59 -0
- autobyteus/agent/workflow/__init__.py +11 -0
- autobyteus/agent/workflow/agentic_workflow.py +89 -0
- autobyteus/agent/workflow/base_agentic_workflow.py +98 -0
- autobyteus/agent/workspace/__init__.py +11 -0
- autobyteus/agent/workspace/base_workspace.py +77 -0
- autobyteus/agent/workspace/workspace_config.py +160 -0
- autobyteus/agent/workspace/workspace_definition.py +36 -0
- autobyteus/agent/workspace/workspace_meta.py +37 -0
- autobyteus/agent/workspace/workspace_registry.py +72 -0
- autobyteus/cli/__init__.py +11 -0
- autobyteus/cli/agent_cli.py +117 -0
- autobyteus/cli/cli_display.py +205 -0
- autobyteus/events/event_emitter.py +33 -56
- autobyteus/events/event_manager.py +134 -66
- autobyteus/events/event_types.py +43 -14
- autobyteus/llm/api/autobyteus_llm.py +13 -25
- autobyteus/llm/api/bedrock_llm.py +9 -3
- autobyteus/llm/api/claude_llm.py +10 -5
- autobyteus/llm/api/deepseek_llm.py +55 -93
- autobyteus/llm/api/gemini_llm.py +10 -4
- autobyteus/llm/api/grok_llm.py +55 -79
- autobyteus/llm/api/groq_llm.py +10 -5
- autobyteus/llm/api/mistral_llm.py +13 -8
- autobyteus/llm/api/nvidia_llm.py +9 -4
- autobyteus/llm/api/ollama_llm.py +58 -50
- autobyteus/llm/api/openai_llm.py +20 -14
- autobyteus/llm/base_llm.py +95 -34
- autobyteus/llm/extensions/base_extension.py +3 -4
- autobyteus/llm/extensions/token_usage_tracking_extension.py +13 -4
- autobyteus/llm/llm_factory.py +116 -53
- autobyteus/llm/models.py +92 -17
- autobyteus/llm/ollama_provider.py +6 -2
- autobyteus/llm/ollama_provider_resolver.py +44 -0
- autobyteus/llm/user_message.py +73 -0
- autobyteus/llm/utils/llm_config.py +124 -27
- autobyteus/llm/utils/response_types.py +3 -2
- autobyteus/llm/utils/token_usage.py +7 -4
- autobyteus/rpc/__init__.py +73 -0
- autobyteus/rpc/client/__init__.py +17 -0
- autobyteus/rpc/client/abstract_client_connection.py +124 -0
- autobyteus/rpc/client/client_connection_manager.py +153 -0
- autobyteus/rpc/client/sse_client_connection.py +306 -0
- autobyteus/rpc/client/stdio_client_connection.py +280 -0
- autobyteus/rpc/config/__init__.py +13 -0
- autobyteus/rpc/config/agent_server_config.py +153 -0
- autobyteus/rpc/config/agent_server_registry.py +152 -0
- autobyteus/rpc/hosting.py +244 -0
- autobyteus/rpc/protocol.py +244 -0
- autobyteus/rpc/server/__init__.py +20 -0
- autobyteus/rpc/server/agent_server_endpoint.py +181 -0
- autobyteus/rpc/server/base_method_handler.py +40 -0
- autobyteus/rpc/server/method_handlers.py +259 -0
- autobyteus/rpc/server/sse_server_handler.py +182 -0
- autobyteus/rpc/server/stdio_server_handler.py +151 -0
- autobyteus/rpc/server_main.py +198 -0
- autobyteus/rpc/transport_type.py +13 -0
- autobyteus/tools/__init__.py +77 -0
- autobyteus/tools/ask_user_input.py +34 -77
- autobyteus/tools/base_tool.py +73 -38
- autobyteus/tools/bash/__init__.py +2 -0
- autobyteus/tools/bash/bash_executor.py +42 -79
- autobyteus/tools/browser/__init__.py +2 -0
- autobyteus/tools/browser/session_aware/browser_session_aware_navigate_to.py +50 -42
- autobyteus/tools/browser/session_aware/browser_session_aware_tool.py +7 -4
- autobyteus/tools/browser/session_aware/browser_session_aware_web_element_trigger.py +117 -125
- autobyteus/tools/browser/session_aware/browser_session_aware_webpage_reader.py +75 -22
- autobyteus/tools/browser/session_aware/browser_session_aware_webpage_screenshot_taker.py +94 -28
- autobyteus/tools/browser/session_aware/factory/browser_session_aware_web_element_trigger_factory.py +10 -2
- autobyteus/tools/browser/session_aware/factory/browser_session_aware_webpage_reader_factory.py +18 -2
- autobyteus/tools/browser/session_aware/factory/browser_session_aware_webpage_screenshot_taker_factory.py +10 -2
- autobyteus/tools/browser/session_aware/shared_browser_session_manager.py +4 -3
- autobyteus/tools/browser/standalone/__init__.py +7 -0
- autobyteus/tools/browser/standalone/factory/google_search_factory.py +17 -2
- autobyteus/tools/browser/standalone/factory/webpage_reader_factory.py +17 -2
- autobyteus/tools/browser/standalone/factory/webpage_screenshot_taker_factory.py +10 -2
- autobyteus/tools/browser/standalone/google_search_ui.py +104 -67
- autobyteus/tools/browser/standalone/navigate_to.py +52 -28
- autobyteus/tools/browser/standalone/web_page_pdf_generator.py +94 -0
- autobyteus/tools/browser/standalone/webpage_image_downloader.py +146 -61
- autobyteus/tools/browser/standalone/webpage_reader.py +80 -61
- autobyteus/tools/browser/standalone/webpage_screenshot_taker.py +91 -45
- autobyteus/tools/factory/__init__.py +9 -0
- autobyteus/tools/factory/tool_factory.py +25 -4
- autobyteus/tools/file/file_reader.py +22 -51
- autobyteus/tools/file/file_writer.py +25 -56
- autobyteus/tools/functional_tool.py +249 -0
- autobyteus/tools/image_downloader.py +49 -71
- autobyteus/tools/mcp/__init__.py +47 -0
- autobyteus/tools/mcp/call_handlers/__init__.py +18 -0
- autobyteus/tools/mcp/call_handlers/base_handler.py +40 -0
- autobyteus/tools/mcp/call_handlers/sse_handler.py +22 -0
- autobyteus/tools/mcp/call_handlers/stdio_handler.py +76 -0
- autobyteus/tools/mcp/call_handlers/streamable_http_handler.py +55 -0
- autobyteus/tools/mcp/config_service.py +237 -0
- autobyteus/tools/mcp/factory.py +70 -0
- autobyteus/tools/mcp/registrar.py +323 -0
- autobyteus/tools/mcp/schema_mapper.py +131 -0
- autobyteus/tools/mcp/tool.py +101 -0
- autobyteus/tools/mcp/types.py +98 -0
- autobyteus/tools/parameter_schema.py +268 -0
- autobyteus/tools/pdf_downloader.py +78 -79
- autobyteus/tools/registry/__init__.py +0 -2
- autobyteus/tools/registry/tool_definition.py +113 -34
- autobyteus/tools/registry/tool_registry.py +64 -22
- autobyteus/tools/timer.py +150 -102
- autobyteus/tools/tool_category.py +11 -0
- autobyteus/tools/tool_config.py +117 -0
- autobyteus/tools/tool_meta.py +50 -26
- autobyteus/tools/tool_state.py +20 -0
- autobyteus/tools/usage/__init__.py +6 -0
- autobyteus/tools/usage/formatters/__init__.py +31 -0
- autobyteus/tools/usage/formatters/anthropic_json_example_formatter.py +18 -0
- autobyteus/tools/usage/formatters/anthropic_json_schema_formatter.py +25 -0
- autobyteus/tools/usage/formatters/base_formatter.py +42 -0
- autobyteus/tools/usage/formatters/default_json_example_formatter.py +42 -0
- autobyteus/tools/usage/formatters/default_json_schema_formatter.py +28 -0
- autobyteus/tools/usage/formatters/default_xml_example_formatter.py +55 -0
- autobyteus/tools/usage/formatters/default_xml_schema_formatter.py +46 -0
- autobyteus/tools/usage/formatters/gemini_json_example_formatter.py +34 -0
- autobyteus/tools/usage/formatters/gemini_json_schema_formatter.py +25 -0
- autobyteus/tools/usage/formatters/google_json_example_formatter.py +34 -0
- autobyteus/tools/usage/formatters/google_json_schema_formatter.py +25 -0
- autobyteus/tools/usage/formatters/openai_json_example_formatter.py +49 -0
- autobyteus/tools/usage/formatters/openai_json_schema_formatter.py +28 -0
- autobyteus/tools/usage/parsers/__init__.py +22 -0
- autobyteus/tools/usage/parsers/anthropic_xml_tool_usage_parser.py +10 -0
- autobyteus/tools/usage/parsers/base_parser.py +41 -0
- autobyteus/tools/usage/parsers/default_json_tool_usage_parser.py +106 -0
- autobyteus/tools/usage/parsers/default_xml_tool_usage_parser.py +136 -0
- autobyteus/tools/usage/parsers/exceptions.py +13 -0
- autobyteus/tools/usage/parsers/gemini_json_tool_usage_parser.py +66 -0
- autobyteus/tools/usage/parsers/openai_json_tool_usage_parser.py +196 -0
- autobyteus/tools/usage/parsers/provider_aware_tool_usage_parser.py +67 -0
- autobyteus/tools/usage/providers/__init__.py +22 -0
- autobyteus/tools/usage/providers/json_example_provider.py +32 -0
- autobyteus/tools/usage/providers/json_schema_provider.py +35 -0
- autobyteus/tools/usage/providers/json_tool_usage_parser_provider.py +28 -0
- autobyteus/tools/usage/providers/tool_manifest_provider.py +68 -0
- autobyteus/tools/usage/providers/xml_example_provider.py +28 -0
- autobyteus/tools/usage/providers/xml_schema_provider.py +29 -0
- autobyteus/tools/usage/providers/xml_tool_usage_parser_provider.py +26 -0
- autobyteus/tools/usage/registries/__init__.py +20 -0
- autobyteus/tools/usage/registries/json_example_formatter_registry.py +51 -0
- autobyteus/tools/usage/registries/json_schema_formatter_registry.py +51 -0
- autobyteus/tools/usage/registries/json_tool_usage_parser_registry.py +42 -0
- autobyteus/tools/usage/registries/xml_example_formatter_registry.py +30 -0
- autobyteus/tools/usage/registries/xml_schema_formatter_registry.py +33 -0
- autobyteus/tools/usage/registries/xml_tool_usage_parser_registry.py +30 -0
- {autobyteus-1.0.6.dist-info → autobyteus-1.1.1.dist-info}/METADATA +23 -5
- autobyteus-1.1.1.dist-info/RECORD +296 -0
- {autobyteus-1.0.6.dist-info → autobyteus-1.1.1.dist-info}/WHEEL +1 -1
- autobyteus/agent/async_agent.py +0 -175
- autobyteus/agent/async_group_aware_agent.py +0 -136
- autobyteus/agent/group/async_group_aware_agent.py +0 -122
- autobyteus/agent/group/coordinator_agent.py +0 -36
- autobyteus/agent/group/group_aware_agent.py +0 -121
- autobyteus/agent/orchestrator/__init__.py +0 -0
- autobyteus/agent/orchestrator/base_agent_orchestrator.py +0 -82
- autobyteus/agent/orchestrator/multi_replica_agent_orchestrator.py +0 -72
- autobyteus/agent/orchestrator/single_replica_agent_orchestrator.py +0 -43
- autobyteus/agent/response_parser/__init__.py +0 -0
- autobyteus/agent/response_parser/tool_usage_command_parser.py +0 -100
- autobyteus/agent/status.py +0 -12
- autobyteus/conversation/__init__.py +0 -0
- autobyteus/conversation/conversation.py +0 -54
- autobyteus/conversation/user_message.py +0 -59
- autobyteus/events/decorators.py +0 -29
- autobyteus/prompt/prompt_version_manager.py +0 -58
- autobyteus/prompt/storage/__init__.py +0 -0
- autobyteus/prompt/storage/prompt_version_model.py +0 -29
- autobyteus/prompt/storage/prompt_version_repository.py +0 -83
- autobyteus/tools/bash/factory/__init__.py +0 -0
- autobyteus/tools/bash/factory/bash_executor_factory.py +0 -6
- autobyteus/tools/factory/ask_user_input_factory.py +0 -6
- autobyteus/tools/factory/image_downloader_factory.py +0 -9
- autobyteus/tools/factory/pdf_downloader_factory.py +0 -9
- autobyteus/tools/factory/webpage_image_downloader_factory.py +0 -6
- autobyteus/tools/file/factory/__init__.py +0 -0
- autobyteus/tools/file/factory/file_reader_factory.py +0 -6
- autobyteus/tools/file/factory/file_writer_factory.py +0 -6
- autobyteus/tools/web_page_pdf_generator.py +0 -90
- autobyteus-1.0.6.dist-info/RECORD +0 -157
- {autobyteus-1.0.6.dist-info → autobyteus-1.1.1.dist-info}/licenses/LICENSE +0 -0
- {autobyteus-1.0.6.dist-info → autobyteus-1.1.1.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# file: autobyteus/autobyteus/tools/tool_state.py
|
|
2
|
+
"""
|
|
3
|
+
Defines the ToolState class, an explicit container for a tool's internal state,
|
|
4
|
+
providing a dictionary-like interface for backward compatibility.
|
|
5
|
+
"""
|
|
6
|
+
from collections import UserDict
|
|
7
|
+
|
|
8
|
+
class ToolState(UserDict):
|
|
9
|
+
"""
|
|
10
|
+
A specialized container for a tool's state.
|
|
11
|
+
|
|
12
|
+
This class inherits from collections.UserDict to provide a dictionary-like
|
|
13
|
+
interface, ensuring that existing tools can interact with the state attribute
|
|
14
|
+
(tool.tool_state) just as they would with a regular dictionary.
|
|
15
|
+
|
|
16
|
+
The primary purpose of this class is to make the concept of a tool's
|
|
17
|
+
state explicit in the framework's type system, improving code clarity
|
|
18
|
+
and developer experience.
|
|
19
|
+
"""
|
|
20
|
+
pass
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# file: autobyteus/autobyteus/tools/usage/formatters/__init__.py
|
|
2
|
+
"""
|
|
3
|
+
This package contains concrete formatter classes that translate a BaseTool's
|
|
4
|
+
metadata into a specific provider's format (e.g., OpenAI JSON, Anthropic JSON, XML).
|
|
5
|
+
"""
|
|
6
|
+
from .base_formatter import BaseSchemaFormatter, BaseExampleFormatter
|
|
7
|
+
from .default_xml_schema_formatter import DefaultXmlSchemaFormatter
|
|
8
|
+
from .default_json_schema_formatter import DefaultJsonSchemaFormatter
|
|
9
|
+
from .openai_json_schema_formatter import OpenAiJsonSchemaFormatter
|
|
10
|
+
from .anthropic_json_schema_formatter import AnthropicJsonSchemaFormatter
|
|
11
|
+
from .gemini_json_schema_formatter import GeminiJsonSchemaFormatter
|
|
12
|
+
from .default_xml_example_formatter import DefaultXmlExampleFormatter
|
|
13
|
+
from .default_json_example_formatter import DefaultJsonExampleFormatter
|
|
14
|
+
from .openai_json_example_formatter import OpenAiJsonExampleFormatter
|
|
15
|
+
from .anthropic_json_example_formatter import AnthropicJsonExampleFormatter
|
|
16
|
+
from .gemini_json_example_formatter import GeminiJsonExampleFormatter
|
|
17
|
+
|
|
18
|
+
__all__ = [
|
|
19
|
+
"BaseSchemaFormatter",
|
|
20
|
+
"BaseExampleFormatter",
|
|
21
|
+
"DefaultXmlSchemaFormatter",
|
|
22
|
+
"DefaultJsonSchemaFormatter",
|
|
23
|
+
"OpenAiJsonSchemaFormatter",
|
|
24
|
+
"AnthropicJsonSchemaFormatter",
|
|
25
|
+
"GeminiJsonSchemaFormatter",
|
|
26
|
+
"DefaultXmlExampleFormatter",
|
|
27
|
+
"DefaultJsonExampleFormatter",
|
|
28
|
+
"OpenAiJsonExampleFormatter",
|
|
29
|
+
"AnthropicJsonExampleFormatter",
|
|
30
|
+
"GeminiJsonExampleFormatter",
|
|
31
|
+
]
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# file: autobyteus/autobyteus/tools/usage/formatters/anthropic_json_example_formatter.py
|
|
2
|
+
from typing import TYPE_CHECKING
|
|
3
|
+
|
|
4
|
+
from .base_formatter import BaseExampleFormatter
|
|
5
|
+
from .default_xml_example_formatter import DefaultXmlExampleFormatter
|
|
6
|
+
|
|
7
|
+
if TYPE_CHECKING:
|
|
8
|
+
from autobyteus.tools.registry import ToolDefinition
|
|
9
|
+
|
|
10
|
+
class AnthropicJsonExampleFormatter(BaseExampleFormatter):
|
|
11
|
+
"""
|
|
12
|
+
Formats a tool usage example for Anthropic models. Since Anthropic uses XML
|
|
13
|
+
for tool calls, this formatter returns a string representing the XML call.
|
|
14
|
+
"""
|
|
15
|
+
def provide(self, tool_definition: 'ToolDefinition') -> str:
|
|
16
|
+
# Anthropic expects XML tool call examples.
|
|
17
|
+
# We use the XML formatter's logic directly.
|
|
18
|
+
return DefaultXmlExampleFormatter().provide(tool_definition)
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# file: autobyteus/autobyteus/tools/usage/formatters/anthropic_json_schema_formatter.py
|
|
2
|
+
from typing import Dict, TYPE_CHECKING
|
|
3
|
+
|
|
4
|
+
from .base_formatter import BaseSchemaFormatter
|
|
5
|
+
|
|
6
|
+
if TYPE_CHECKING:
|
|
7
|
+
from autobyteus.tools.registry import ToolDefinition
|
|
8
|
+
|
|
9
|
+
class AnthropicJsonSchemaFormatter(BaseSchemaFormatter):
|
|
10
|
+
"""Formats a tool's schema into the Anthropic JSON format."""
|
|
11
|
+
|
|
12
|
+
def provide(self, tool_definition: 'ToolDefinition') -> Dict:
|
|
13
|
+
name = tool_definition.name
|
|
14
|
+
description = tool_definition.description
|
|
15
|
+
arg_schema = tool_definition.argument_schema
|
|
16
|
+
|
|
17
|
+
input_schema = arg_schema.to_json_schema_dict() if arg_schema else {
|
|
18
|
+
"type": "object", "properties": {}, "required": []
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return {
|
|
22
|
+
"name": name,
|
|
23
|
+
"description": description,
|
|
24
|
+
"input_schema": input_schema,
|
|
25
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# file: autobyteus/autobyteus/tools/usage/formatters/base_formatter.py
|
|
2
|
+
from abc import ABC, abstractmethod
|
|
3
|
+
from typing import Union, Dict, TYPE_CHECKING
|
|
4
|
+
|
|
5
|
+
if TYPE_CHECKING:
|
|
6
|
+
from autobyteus.tools.registry import ToolDefinition
|
|
7
|
+
|
|
8
|
+
class BaseSchemaFormatter(ABC):
|
|
9
|
+
"""
|
|
10
|
+
Abstract base class for formatting the schema of a single tool
|
|
11
|
+
into a provider-specific format.
|
|
12
|
+
"""
|
|
13
|
+
@abstractmethod
|
|
14
|
+
def provide(self, tool_definition: 'ToolDefinition') -> Union[str, Dict]:
|
|
15
|
+
"""
|
|
16
|
+
Formats the schema of the given tool definition.
|
|
17
|
+
|
|
18
|
+
Args:
|
|
19
|
+
tool_definition: The tool definition to format.
|
|
20
|
+
|
|
21
|
+
Returns:
|
|
22
|
+
An XML string or a dictionary representing the tool's schema.
|
|
23
|
+
"""
|
|
24
|
+
pass
|
|
25
|
+
|
|
26
|
+
class BaseExampleFormatter(ABC):
|
|
27
|
+
"""
|
|
28
|
+
Abstract base class for formatting a usage example of a single tool
|
|
29
|
+
into a provider-specific format.
|
|
30
|
+
"""
|
|
31
|
+
@abstractmethod
|
|
32
|
+
def provide(self, tool_definition: 'ToolDefinition') -> Union[str, Dict]:
|
|
33
|
+
"""
|
|
34
|
+
Formats a usage example for the given tool definition.
|
|
35
|
+
|
|
36
|
+
Args:
|
|
37
|
+
tool_definition: The tool definition to format an example for.
|
|
38
|
+
|
|
39
|
+
Returns:
|
|
40
|
+
An XML string or a dictionary representing a tool usage example.
|
|
41
|
+
"""
|
|
42
|
+
pass
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# file: autobyteus/autobyteus/tools/usage/formatters/default_json_example_formatter.py
|
|
2
|
+
from typing import Dict, Any, TYPE_CHECKING
|
|
3
|
+
|
|
4
|
+
from autobyteus.tools.parameter_schema import ParameterType, ParameterDefinition
|
|
5
|
+
from .base_formatter import BaseExampleFormatter
|
|
6
|
+
|
|
7
|
+
if TYPE_CHECKING:
|
|
8
|
+
from autobyteus.tools.registry import ToolDefinition
|
|
9
|
+
|
|
10
|
+
class DefaultJsonExampleFormatter(BaseExampleFormatter):
|
|
11
|
+
"""
|
|
12
|
+
Formats a tool usage example into a generic JSON format, inspired by
|
|
13
|
+
the default XML format.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
def provide(self, tool_definition: 'ToolDefinition') -> Dict:
|
|
17
|
+
tool_name = tool_definition.name
|
|
18
|
+
arg_schema = tool_definition.argument_schema
|
|
19
|
+
arguments = {}
|
|
20
|
+
|
|
21
|
+
if arg_schema and arg_schema.parameters:
|
|
22
|
+
for param_def in arg_schema.parameters:
|
|
23
|
+
if param_def.required or param_def.default_value is not None:
|
|
24
|
+
arguments[param_def.name] = self._generate_placeholder_value(param_def)
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
"tool": {
|
|
28
|
+
"function": tool_name,
|
|
29
|
+
"parameters": arguments,
|
|
30
|
+
},
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
def _generate_placeholder_value(self, param_def: ParameterDefinition) -> Any:
|
|
34
|
+
if param_def.default_value is not None: return param_def.default_value
|
|
35
|
+
if param_def.param_type == ParameterType.STRING: return f"example_{param_def.name}"
|
|
36
|
+
if param_def.param_type == ParameterType.INTEGER: return 123
|
|
37
|
+
if param_def.param_type == ParameterType.FLOAT: return 123.45
|
|
38
|
+
if param_def.param_type == ParameterType.BOOLEAN: return True
|
|
39
|
+
if param_def.param_type == ParameterType.ENUM: return param_def.enum_values[0] if param_def.enum_values else "enum_val"
|
|
40
|
+
if param_def.param_type == ParameterType.OBJECT: return {"key": "value"}
|
|
41
|
+
if param_def.param_type == ParameterType.ARRAY: return ["item1", "item2"]
|
|
42
|
+
return "placeholder"
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# file: autobyteus/autobyteus/tools/usage/formatters/default_json_schema_formatter.py
|
|
2
|
+
from typing import Dict, TYPE_CHECKING
|
|
3
|
+
|
|
4
|
+
from .base_formatter import BaseSchemaFormatter
|
|
5
|
+
|
|
6
|
+
if TYPE_CHECKING:
|
|
7
|
+
from autobyteus.tools.registry import ToolDefinition
|
|
8
|
+
|
|
9
|
+
class DefaultJsonSchemaFormatter(BaseSchemaFormatter):
|
|
10
|
+
"""
|
|
11
|
+
Formats a tool's schema into a generic, provider-agnostic JSON format.
|
|
12
|
+
This serves as the default for JSON-based schema representation.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
def provide(self, tool_definition: 'ToolDefinition') -> Dict:
|
|
16
|
+
name = tool_definition.name
|
|
17
|
+
description = tool_definition.description
|
|
18
|
+
arg_schema = tool_definition.argument_schema
|
|
19
|
+
|
|
20
|
+
input_schema = arg_schema.to_json_schema_dict() if arg_schema else {
|
|
21
|
+
"type": "object", "properties": {}, "required": []
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
"name": name,
|
|
26
|
+
"description": description,
|
|
27
|
+
"inputSchema": input_schema,
|
|
28
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# file: autobyteus/autobyteus/tools/usage/formatters/default_xml_example_formatter.py
|
|
2
|
+
import xml.sax.saxutils
|
|
3
|
+
from typing import Any, TYPE_CHECKING
|
|
4
|
+
|
|
5
|
+
from autobyteus.tools.parameter_schema import ParameterType, ParameterDefinition
|
|
6
|
+
from .base_formatter import BaseExampleFormatter
|
|
7
|
+
|
|
8
|
+
if TYPE_CHECKING:
|
|
9
|
+
from autobyteus.tools.registry import ToolDefinition
|
|
10
|
+
|
|
11
|
+
class DefaultXmlExampleFormatter(BaseExampleFormatter):
|
|
12
|
+
"""Formats a tool usage example into a standardized XML <tool> string."""
|
|
13
|
+
|
|
14
|
+
def provide(self, tool_definition: 'ToolDefinition') -> str:
|
|
15
|
+
tool_name = tool_definition.name
|
|
16
|
+
arg_schema = tool_definition.argument_schema
|
|
17
|
+
|
|
18
|
+
example_xml_parts = [f'<tool name="{tool_name}">']
|
|
19
|
+
arguments_part = []
|
|
20
|
+
|
|
21
|
+
if arg_schema and arg_schema.parameters:
|
|
22
|
+
for param_def in arg_schema.parameters:
|
|
23
|
+
if param_def.required or param_def.default_value is not None:
|
|
24
|
+
placeholder_value = self._generate_placeholder_value(param_def)
|
|
25
|
+
escaped_value = xml.sax.saxutils.escape(str(placeholder_value))
|
|
26
|
+
arguments_part.append(f' <arg name="{param_def.name}">{escaped_value}</arg>')
|
|
27
|
+
|
|
28
|
+
if arguments_part:
|
|
29
|
+
example_xml_parts.append(" <arguments>")
|
|
30
|
+
example_xml_parts.extend(arguments_part)
|
|
31
|
+
example_xml_parts.append(" </arguments>")
|
|
32
|
+
else:
|
|
33
|
+
example_xml_parts.append(" <!-- This tool takes no arguments -->")
|
|
34
|
+
|
|
35
|
+
example_xml_parts.append("</tool>")
|
|
36
|
+
return "\n".join(example_xml_parts)
|
|
37
|
+
|
|
38
|
+
def _generate_placeholder_value(self, param_def: ParameterDefinition) -> Any:
|
|
39
|
+
if param_def.default_value is not None:
|
|
40
|
+
return param_def.default_value
|
|
41
|
+
if param_def.param_type == ParameterType.STRING:
|
|
42
|
+
return f"example_{param_def.name}"
|
|
43
|
+
if param_def.param_type == ParameterType.INTEGER:
|
|
44
|
+
return 123
|
|
45
|
+
if param_def.param_type == ParameterType.FLOAT:
|
|
46
|
+
return 123.45
|
|
47
|
+
if param_def.param_type == ParameterType.BOOLEAN:
|
|
48
|
+
return True
|
|
49
|
+
if param_def.param_type == ParameterType.ENUM:
|
|
50
|
+
return param_def.enum_values[0] if param_def.enum_values else "enum_val"
|
|
51
|
+
if param_def.param_type == ParameterType.OBJECT:
|
|
52
|
+
return {"key": "value"}
|
|
53
|
+
if param_def.param_type == ParameterType.ARRAY:
|
|
54
|
+
return ["item1", "item2"]
|
|
55
|
+
return "placeholder"
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# file: autobyteus/autobyteus/tools/usage/formatters/default_xml_schema_formatter.py
|
|
2
|
+
import xml.sax.saxutils
|
|
3
|
+
from typing import TYPE_CHECKING
|
|
4
|
+
|
|
5
|
+
from autobyteus.tools.parameter_schema import ParameterType
|
|
6
|
+
from .base_formatter import BaseSchemaFormatter
|
|
7
|
+
|
|
8
|
+
if TYPE_CHECKING:
|
|
9
|
+
from autobyteus.tools.registry import ToolDefinition
|
|
10
|
+
|
|
11
|
+
class DefaultXmlSchemaFormatter(BaseSchemaFormatter):
|
|
12
|
+
"""Formats a tool's schema into a standardized XML string."""
|
|
13
|
+
|
|
14
|
+
def provide(self, tool_definition: 'ToolDefinition') -> str:
|
|
15
|
+
arg_schema = tool_definition.argument_schema
|
|
16
|
+
tool_name = tool_definition.name
|
|
17
|
+
description = tool_definition.description
|
|
18
|
+
|
|
19
|
+
escaped_description = xml.sax.saxutils.escape(description) if description else ""
|
|
20
|
+
tool_tag = f'<tool name="{tool_name}" description="{escaped_description}">'
|
|
21
|
+
xml_parts = [tool_tag]
|
|
22
|
+
|
|
23
|
+
if arg_schema and arg_schema.parameters:
|
|
24
|
+
xml_parts.append(" <arguments>")
|
|
25
|
+
for param in arg_schema.parameters:
|
|
26
|
+
arg_tag = f' <arg name="{param.name}"'
|
|
27
|
+
arg_tag += f' type="{param.param_type.value}"'
|
|
28
|
+
if param.description:
|
|
29
|
+
escaped_param_desc = xml.sax.saxutils.escape(param.description)
|
|
30
|
+
arg_tag += f' description="{escaped_param_desc}"'
|
|
31
|
+
arg_tag += f" required=\"{'true' if param.required else 'false'}\""
|
|
32
|
+
|
|
33
|
+
if param.default_value is not None:
|
|
34
|
+
arg_tag += f' default="{xml.sax.saxutils.escape(str(param.default_value))}"'
|
|
35
|
+
if param.param_type == ParameterType.ENUM and param.enum_values:
|
|
36
|
+
escaped_enum_values = [xml.sax.saxutils.escape(ev) for ev in param.enum_values]
|
|
37
|
+
arg_tag += f' enum_values="{",".join(escaped_enum_values)}"'
|
|
38
|
+
|
|
39
|
+
arg_tag += " />"
|
|
40
|
+
xml_parts.append(arg_tag)
|
|
41
|
+
xml_parts.append(" </arguments>")
|
|
42
|
+
else:
|
|
43
|
+
xml_parts.append(" <!-- This tool takes no arguments -->")
|
|
44
|
+
|
|
45
|
+
xml_parts.append("</tool>")
|
|
46
|
+
return "\n".join(xml_parts)
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# file: autobyteus/autobyteus/tools/usage/formatters/gemini_json_example_formatter.py
|
|
2
|
+
from typing import Dict, Any, TYPE_CHECKING
|
|
3
|
+
|
|
4
|
+
from autobyteus.tools.parameter_schema import ParameterType, ParameterDefinition
|
|
5
|
+
from .base_formatter import BaseExampleFormatter
|
|
6
|
+
|
|
7
|
+
if TYPE_CHECKING:
|
|
8
|
+
from autobyteus.tools.registry import ToolDefinition
|
|
9
|
+
|
|
10
|
+
class GeminiJsonExampleFormatter(BaseExampleFormatter):
|
|
11
|
+
"""Formats a tool usage example into the Google Gemini tool_calls format."""
|
|
12
|
+
|
|
13
|
+
def provide(self, tool_definition: 'ToolDefinition') -> Dict:
|
|
14
|
+
tool_name = tool_definition.name
|
|
15
|
+
arg_schema = tool_definition.argument_schema
|
|
16
|
+
arguments = {}
|
|
17
|
+
|
|
18
|
+
if arg_schema and arg_schema.parameters:
|
|
19
|
+
for param_def in arg_schema.parameters:
|
|
20
|
+
if param_def.required or param_def.default_value is not None:
|
|
21
|
+
arguments[param_def.name] = self._generate_placeholder_value(param_def)
|
|
22
|
+
|
|
23
|
+
return {"name": tool_name, "args": arguments}
|
|
24
|
+
|
|
25
|
+
def _generate_placeholder_value(self, param_def: ParameterDefinition) -> Any:
|
|
26
|
+
if param_def.default_value is not None: return param_def.default_value
|
|
27
|
+
if param_def.param_type == ParameterType.STRING: return f"example_{param_def.name}"
|
|
28
|
+
if param_def.param_type == ParameterType.INTEGER: return 123
|
|
29
|
+
if param_def.param_type == ParameterType.FLOAT: return 123.45
|
|
30
|
+
if param_def.param_type == ParameterType.BOOLEAN: return True
|
|
31
|
+
if param_def.param_type == ParameterType.ENUM: return param_def.enum_values[0] if param_def.enum_values else "enum_val"
|
|
32
|
+
if param_def.param_type == ParameterType.OBJECT: return {"key": "value"}
|
|
33
|
+
if param_def.param_type == ParameterType.ARRAY: return ["item1", "item2"]
|
|
34
|
+
return "placeholder"
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# file: autobyteus/autobyteus/tools/usage/formatters/gemini_json_schema_formatter.py
|
|
2
|
+
from typing import Dict, TYPE_CHECKING
|
|
3
|
+
|
|
4
|
+
from .base_formatter import BaseSchemaFormatter
|
|
5
|
+
|
|
6
|
+
if TYPE_CHECKING:
|
|
7
|
+
from autobyteus.tools.registry import ToolDefinition
|
|
8
|
+
|
|
9
|
+
class GeminiJsonSchemaFormatter(BaseSchemaFormatter):
|
|
10
|
+
"""Formats a tool's schema into a Google Gemini function declaration format."""
|
|
11
|
+
|
|
12
|
+
def provide(self, tool_definition: 'ToolDefinition') -> Dict:
|
|
13
|
+
name = tool_definition.name
|
|
14
|
+
description = tool_definition.description
|
|
15
|
+
arg_schema = tool_definition.argument_schema
|
|
16
|
+
|
|
17
|
+
parameters = arg_schema.to_json_schema_dict() if arg_schema else {
|
|
18
|
+
"type": "object", "properties": {}, "required": []
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return {
|
|
22
|
+
"name": name,
|
|
23
|
+
"description": description,
|
|
24
|
+
"parameters": parameters,
|
|
25
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# file: autobyteus/autobyteus/tools/usage/formatters/google_json_example_formatter.py
|
|
2
|
+
from typing import Dict, Any, TYPE_CHECKING
|
|
3
|
+
|
|
4
|
+
from autobyteus.tools.parameter_schema import ParameterType, ParameterDefinition
|
|
5
|
+
from .base_formatter import BaseExampleFormatter
|
|
6
|
+
|
|
7
|
+
if TYPE_CHECKING:
|
|
8
|
+
from autobyteus.tools.registry import ToolDefinition
|
|
9
|
+
|
|
10
|
+
class GoogleJsonExampleFormatter(BaseExampleFormatter):
|
|
11
|
+
"""Formats a tool usage example into the Google JSON tool_calls format."""
|
|
12
|
+
|
|
13
|
+
def provide(self, tool_definition: 'ToolDefinition') -> Dict:
|
|
14
|
+
tool_name = tool_definition.name
|
|
15
|
+
arg_schema = tool_definition.argument_schema
|
|
16
|
+
arguments = {}
|
|
17
|
+
|
|
18
|
+
if arg_schema and arg_schema.parameters:
|
|
19
|
+
for param_def in arg_schema.parameters:
|
|
20
|
+
if param_def.required or param_def.default_value is not None:
|
|
21
|
+
arguments[param_def.name] = self._generate_placeholder_value(param_def)
|
|
22
|
+
|
|
23
|
+
return {"name": tool_name, "args": arguments}
|
|
24
|
+
|
|
25
|
+
def _generate_placeholder_value(self, param_def: ParameterDefinition) -> Any:
|
|
26
|
+
if param_def.default_value is not None: return param_def.default_value
|
|
27
|
+
if param_def.param_type == ParameterType.STRING: return f"example_{param_def.name}"
|
|
28
|
+
if param_def.param_type == ParameterType.INTEGER: return 123
|
|
29
|
+
if param_def.param_type == ParameterType.FLOAT: return 123.45
|
|
30
|
+
if param_def.param_type == ParameterType.BOOLEAN: return True
|
|
31
|
+
if param_def.param_type == ParameterType.ENUM: return param_def.enum_values[0] if param_def.enum_values else "enum_val"
|
|
32
|
+
if param_def.param_type == ParameterType.OBJECT: return {"key": "value"}
|
|
33
|
+
if param_def.param_type == ParameterType.ARRAY: return ["item1", "item2"]
|
|
34
|
+
return "placeholder"
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# file: autobyteus/autobyteus/tools/usage/formatters/google_json_schema_formatter.py
|
|
2
|
+
from typing import Dict, TYPE_CHECKING
|
|
3
|
+
|
|
4
|
+
from .base_formatter import BaseSchemaFormatter
|
|
5
|
+
|
|
6
|
+
if TYPE_CHECKING:
|
|
7
|
+
from autobyteus.tools.registry import ToolDefinition
|
|
8
|
+
|
|
9
|
+
class GoogleJsonSchemaFormatter(BaseSchemaFormatter):
|
|
10
|
+
"""Formats a tool's schema into a Google function declaration format."""
|
|
11
|
+
|
|
12
|
+
def provide(self, tool_definition: 'ToolDefinition') -> Dict:
|
|
13
|
+
name = tool_definition.name
|
|
14
|
+
description = tool_definition.description
|
|
15
|
+
arg_schema = tool_definition.argument_schema
|
|
16
|
+
|
|
17
|
+
parameters = arg_schema.to_json_schema_dict() if arg_schema else {
|
|
18
|
+
"type": "object", "properties": {}, "required": []
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return {
|
|
22
|
+
"name": name,
|
|
23
|
+
"description": description,
|
|
24
|
+
"parameters": parameters,
|
|
25
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# file: autobyteus/autobyteus/tools/usage/formatters/openai_json_example_formatter.py
|
|
2
|
+
import json
|
|
3
|
+
from typing import Dict, Any, TYPE_CHECKING
|
|
4
|
+
|
|
5
|
+
from autobyteus.tools.parameter_schema import ParameterType, ParameterDefinition
|
|
6
|
+
from .base_formatter import BaseExampleFormatter
|
|
7
|
+
|
|
8
|
+
if TYPE_CHECKING:
|
|
9
|
+
from autobyteus.tools.registry import ToolDefinition
|
|
10
|
+
|
|
11
|
+
class OpenAiJsonExampleFormatter(BaseExampleFormatter):
|
|
12
|
+
"""
|
|
13
|
+
Formats a tool usage example into a format resembling an entry in the
|
|
14
|
+
OpenAI JSON 'tool_calls' array, intended for prompting a model.
|
|
15
|
+
The output is wrapped in a 'tool' key for consistency in prompts.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
def provide(self, tool_definition: 'ToolDefinition') -> Dict:
|
|
19
|
+
tool_name = tool_definition.name
|
|
20
|
+
arg_schema = tool_definition.argument_schema
|
|
21
|
+
arguments = {}
|
|
22
|
+
|
|
23
|
+
if arg_schema and arg_schema.parameters:
|
|
24
|
+
for param_def in arg_schema.parameters:
|
|
25
|
+
if param_def.required or param_def.default_value is not None:
|
|
26
|
+
arguments[param_def.name] = self._generate_placeholder_value(param_def)
|
|
27
|
+
|
|
28
|
+
# This format contains the 'function' wrapper with a stringified 'arguments' field.
|
|
29
|
+
# This aligns with the structure often seen inside an OpenAI API tool_calls object.
|
|
30
|
+
function_call = {
|
|
31
|
+
"function": {
|
|
32
|
+
"name": tool_name,
|
|
33
|
+
"arguments": json.dumps(arguments),
|
|
34
|
+
},
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
# Wrap in a 'tool' key for consistency in prompt generation.
|
|
38
|
+
return {"tool": function_call}
|
|
39
|
+
|
|
40
|
+
def _generate_placeholder_value(self, param_def: ParameterDefinition) -> Any:
|
|
41
|
+
if param_def.default_value is not None: return param_def.default_value
|
|
42
|
+
if param_def.param_type == ParameterType.STRING: return f"example_{param_def.name}"
|
|
43
|
+
if param_def.param_type == ParameterType.INTEGER: return 123
|
|
44
|
+
if param_def.param_type == ParameterType.FLOAT: return 123.45
|
|
45
|
+
if param_def.param_type == ParameterType.BOOLEAN: return True
|
|
46
|
+
if param_def.param_type == ParameterType.ENUM: return param_def.enum_values[0] if param_def.enum_values else "enum_val"
|
|
47
|
+
if param_def.param_type == ParameterType.OBJECT: return {"key": "value"}
|
|
48
|
+
if param_def.param_type == ParameterType.ARRAY: return ["item1", "item2"]
|
|
49
|
+
return "placeholder"
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# file: autobyteus/autobyteus/tools/usage/formatters/openai_json_schema_formatter.py
|
|
2
|
+
from typing import Dict, TYPE_CHECKING
|
|
3
|
+
|
|
4
|
+
from .base_formatter import BaseSchemaFormatter
|
|
5
|
+
|
|
6
|
+
if TYPE_CHECKING:
|
|
7
|
+
from autobyteus.tools.registry import ToolDefinition
|
|
8
|
+
|
|
9
|
+
class OpenAiJsonSchemaFormatter(BaseSchemaFormatter):
|
|
10
|
+
"""Formats a tool's schema into the OpenAI JSON function format."""
|
|
11
|
+
|
|
12
|
+
def provide(self, tool_definition: 'ToolDefinition') -> Dict:
|
|
13
|
+
name = tool_definition.name
|
|
14
|
+
description = tool_definition.description
|
|
15
|
+
arg_schema = tool_definition.argument_schema
|
|
16
|
+
|
|
17
|
+
parameters = arg_schema.to_json_schema_dict() if arg_schema else {
|
|
18
|
+
"type": "object", "properties": {}, "required": []
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return {
|
|
22
|
+
"type": "function",
|
|
23
|
+
"function": {
|
|
24
|
+
"name": name,
|
|
25
|
+
"description": description,
|
|
26
|
+
"parameters": parameters,
|
|
27
|
+
},
|
|
28
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# file: autobyteus/autobyteus/tools/usage/parsers/__init__.py
|
|
2
|
+
"""
|
|
3
|
+
This package contains concrete parser classes that translate an LLM's raw response
|
|
4
|
+
text into structured ToolInvocation objects.
|
|
5
|
+
"""
|
|
6
|
+
from .base_parser import BaseToolUsageParser
|
|
7
|
+
from .provider_aware_tool_usage_parser import ProviderAwareToolUsageParser
|
|
8
|
+
from .default_xml_tool_usage_parser import DefaultXmlToolUsageParser
|
|
9
|
+
from .anthropic_xml_tool_usage_parser import AnthropicXmlToolUsageParser
|
|
10
|
+
from .default_json_tool_usage_parser import DefaultJsonToolUsageParser
|
|
11
|
+
from .openai_json_tool_usage_parser import OpenAiJsonToolUsageParser
|
|
12
|
+
from .gemini_json_tool_usage_parser import GeminiJsonToolUsageParser
|
|
13
|
+
|
|
14
|
+
__all__ = [
|
|
15
|
+
"BaseToolUsageParser",
|
|
16
|
+
"ProviderAwareToolUsageParser",
|
|
17
|
+
"DefaultXmlToolUsageParser",
|
|
18
|
+
"AnthropicXmlToolUsageParser",
|
|
19
|
+
"DefaultJsonToolUsageParser",
|
|
20
|
+
"OpenAiJsonToolUsageParser",
|
|
21
|
+
"GeminiJsonToolUsageParser",
|
|
22
|
+
]
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# file: autobyteus/autobyteus/tools/usage/parsers/anthropic_xml_tool_usage_parser.py
|
|
2
|
+
from .default_xml_tool_usage_parser import DefaultXmlToolUsageParser
|
|
3
|
+
|
|
4
|
+
class AnthropicXmlToolUsageParser(DefaultXmlToolUsageParser):
|
|
5
|
+
"""
|
|
6
|
+
Parser for Anthropic models. Anthropic uses XML for tool calls,
|
|
7
|
+
so this is an alias for the default XML parser.
|
|
8
|
+
"""
|
|
9
|
+
def get_name(self) -> str:
|
|
10
|
+
return "anthropic_xml_tool_usage_parser"
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# file: autobyteus/autobyteus/tools/usage/parsers/base_parser.py
|
|
2
|
+
import logging
|
|
3
|
+
from abc import ABC, abstractmethod
|
|
4
|
+
from typing import List, TYPE_CHECKING
|
|
5
|
+
|
|
6
|
+
if TYPE_CHECKING:
|
|
7
|
+
from autobyteus.agent.tool_invocation import ToolInvocation
|
|
8
|
+
from autobyteus.llm.utils.response_types import CompleteResponse
|
|
9
|
+
|
|
10
|
+
logger = logging.getLogger(__name__)
|
|
11
|
+
|
|
12
|
+
class BaseToolUsageParser(ABC):
|
|
13
|
+
"""
|
|
14
|
+
Abstract base class for parsing tool usage from an LLM's response text.
|
|
15
|
+
These parsers are responsible for extracting structured tool call information.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
def get_name(self) -> str:
|
|
19
|
+
"""
|
|
20
|
+
Returns the unique name for this parser.
|
|
21
|
+
Defaults to the class name.
|
|
22
|
+
"""
|
|
23
|
+
return self.__class__.__name__
|
|
24
|
+
|
|
25
|
+
@abstractmethod
|
|
26
|
+
def parse(self, response: 'CompleteResponse') -> List['ToolInvocation']:
|
|
27
|
+
"""
|
|
28
|
+
Parses the LLM's response. If actionable tool calls are found,
|
|
29
|
+
this method should return a list of ToolInvocation objects.
|
|
30
|
+
|
|
31
|
+
Args:
|
|
32
|
+
response: The CompleteResponse object from the LLM.
|
|
33
|
+
|
|
34
|
+
Returns:
|
|
35
|
+
A list of ToolInvocation objects. Returns an empty list if no
|
|
36
|
+
valid tool calls are found.
|
|
37
|
+
"""
|
|
38
|
+
raise NotImplementedError("Subclasses must implement the 'parse' method.")
|
|
39
|
+
|
|
40
|
+
def __repr__(self) -> str:
|
|
41
|
+
return f"<{self.__class__.__name__}>"
|