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.
Files changed (270) hide show
  1. autobyteus/agent/agent.py +97 -222
  2. autobyteus/agent/bootstrap_steps/__init__.py +19 -0
  3. autobyteus/agent/bootstrap_steps/agent_bootstrapper.py +88 -0
  4. autobyteus/agent/bootstrap_steps/agent_runtime_queue_initialization_step.py +57 -0
  5. autobyteus/agent/bootstrap_steps/base_bootstrap_step.py +38 -0
  6. autobyteus/agent/bootstrap_steps/system_prompt_processing_step.py +93 -0
  7. autobyteus/agent/bootstrap_steps/workspace_context_initialization_step.py +47 -0
  8. autobyteus/agent/context/__init__.py +13 -0
  9. autobyteus/agent/context/agent_config.py +84 -0
  10. autobyteus/agent/context/agent_context.py +129 -0
  11. autobyteus/agent/context/agent_phase_manager.py +264 -0
  12. autobyteus/agent/context/agent_runtime_state.py +89 -0
  13. autobyteus/agent/context/phases.py +49 -0
  14. autobyteus/agent/events/__init__.py +52 -0
  15. autobyteus/agent/events/agent_events.py +110 -0
  16. autobyteus/agent/events/agent_input_event_queue_manager.py +174 -0
  17. autobyteus/agent/events/notifiers.py +122 -0
  18. autobyteus/agent/events/worker_event_dispatcher.py +118 -0
  19. autobyteus/agent/factory/__init__.py +9 -0
  20. autobyteus/agent/factory/agent_factory.py +145 -0
  21. autobyteus/agent/group/agent_group.py +164 -0
  22. autobyteus/agent/group/agent_group_context.py +81 -0
  23. autobyteus/agent/handlers/__init__.py +36 -0
  24. autobyteus/agent/handlers/approved_tool_invocation_event_handler.py +148 -0
  25. autobyteus/agent/handlers/base_event_handler.py +36 -0
  26. autobyteus/agent/handlers/event_handler_registry.py +76 -0
  27. autobyteus/agent/handlers/generic_event_handler.py +46 -0
  28. autobyteus/agent/handlers/inter_agent_message_event_handler.py +76 -0
  29. autobyteus/agent/handlers/lifecycle_event_logger.py +64 -0
  30. autobyteus/agent/handlers/llm_complete_response_received_event_handler.py +138 -0
  31. autobyteus/agent/handlers/llm_user_message_ready_event_handler.py +140 -0
  32. autobyteus/agent/handlers/tool_execution_approval_event_handler.py +85 -0
  33. autobyteus/agent/handlers/tool_invocation_request_event_handler.py +211 -0
  34. autobyteus/agent/handlers/tool_result_event_handler.py +101 -0
  35. autobyteus/agent/handlers/user_input_message_event_handler.py +77 -0
  36. autobyteus/agent/hooks/__init__.py +16 -0
  37. autobyteus/agent/hooks/base_phase_hook.py +61 -0
  38. autobyteus/agent/hooks/hook_definition.py +36 -0
  39. autobyteus/agent/hooks/hook_meta.py +37 -0
  40. autobyteus/agent/hooks/hook_registry.py +118 -0
  41. autobyteus/agent/input_processor/__init__.py +18 -0
  42. autobyteus/agent/input_processor/base_user_input_processor.py +54 -0
  43. autobyteus/agent/input_processor/content_prefixing_input_processor.py +41 -0
  44. autobyteus/agent/input_processor/metadata_appending_input_processor.py +34 -0
  45. autobyteus/agent/input_processor/passthrough_input_processor.py +33 -0
  46. autobyteus/agent/input_processor/processor_definition.py +42 -0
  47. autobyteus/agent/input_processor/processor_meta.py +46 -0
  48. autobyteus/agent/input_processor/processor_registry.py +117 -0
  49. autobyteus/agent/llm_response_processor/__init__.py +16 -0
  50. autobyteus/agent/llm_response_processor/base_processor.py +53 -0
  51. autobyteus/agent/llm_response_processor/processor_definition.py +36 -0
  52. autobyteus/agent/llm_response_processor/processor_meta.py +37 -0
  53. autobyteus/agent/llm_response_processor/processor_registry.py +113 -0
  54. autobyteus/agent/llm_response_processor/provider_aware_tool_usage_processor.py +54 -0
  55. autobyteus/agent/message/__init__.py +20 -0
  56. autobyteus/agent/message/agent_input_user_message.py +96 -0
  57. autobyteus/agent/message/context_file.py +82 -0
  58. autobyteus/agent/message/context_file_type.py +63 -0
  59. autobyteus/agent/message/{message.py → inter_agent_message.py} +12 -12
  60. autobyteus/agent/message/{message_types.py → inter_agent_message_type.py} +8 -6
  61. autobyteus/agent/message/send_message_to.py +142 -36
  62. autobyteus/agent/phases/__init__.py +18 -0
  63. autobyteus/agent/phases/discover.py +52 -0
  64. autobyteus/agent/phases/manager.py +265 -0
  65. autobyteus/agent/phases/phase_enum.py +49 -0
  66. autobyteus/agent/phases/transition_decorator.py +40 -0
  67. autobyteus/agent/phases/transition_info.py +33 -0
  68. autobyteus/agent/remote_agent.py +244 -0
  69. autobyteus/agent/runtime/__init__.py +15 -0
  70. autobyteus/agent/runtime/agent_runtime.py +137 -0
  71. autobyteus/agent/runtime/agent_thread_pool_manager.py +88 -0
  72. autobyteus/agent/runtime/agent_worker.py +200 -0
  73. autobyteus/agent/streaming/__init__.py +15 -0
  74. autobyteus/agent/streaming/agent_event_stream.py +173 -0
  75. autobyteus/agent/streaming/queue_streamer.py +58 -0
  76. autobyteus/agent/streaming/stream_event_payloads.py +167 -0
  77. autobyteus/agent/streaming/stream_events.py +126 -0
  78. autobyteus/agent/system_prompt_processor/__init__.py +14 -0
  79. autobyteus/agent/system_prompt_processor/base_processor.py +48 -0
  80. autobyteus/agent/system_prompt_processor/processor_definition.py +40 -0
  81. autobyteus/agent/system_prompt_processor/processor_meta.py +47 -0
  82. autobyteus/agent/system_prompt_processor/processor_registry.py +119 -0
  83. autobyteus/agent/system_prompt_processor/tool_manifest_injector_processor.py +79 -0
  84. autobyteus/agent/tool_invocation.py +54 -5
  85. autobyteus/agent/utils/__init__.py +9 -0
  86. autobyteus/agent/utils/wait_for_idle.py +59 -0
  87. autobyteus/agent/workflow/__init__.py +11 -0
  88. autobyteus/agent/workflow/agentic_workflow.py +89 -0
  89. autobyteus/agent/workflow/base_agentic_workflow.py +98 -0
  90. autobyteus/agent/workspace/__init__.py +11 -0
  91. autobyteus/agent/workspace/base_workspace.py +77 -0
  92. autobyteus/agent/workspace/workspace_config.py +160 -0
  93. autobyteus/agent/workspace/workspace_definition.py +36 -0
  94. autobyteus/agent/workspace/workspace_meta.py +37 -0
  95. autobyteus/agent/workspace/workspace_registry.py +72 -0
  96. autobyteus/cli/__init__.py +11 -0
  97. autobyteus/cli/agent_cli.py +117 -0
  98. autobyteus/cli/cli_display.py +205 -0
  99. autobyteus/events/event_emitter.py +33 -56
  100. autobyteus/events/event_manager.py +134 -66
  101. autobyteus/events/event_types.py +43 -14
  102. autobyteus/llm/api/autobyteus_llm.py +13 -25
  103. autobyteus/llm/api/bedrock_llm.py +9 -3
  104. autobyteus/llm/api/claude_llm.py +10 -5
  105. autobyteus/llm/api/deepseek_llm.py +55 -93
  106. autobyteus/llm/api/gemini_llm.py +10 -4
  107. autobyteus/llm/api/grok_llm.py +55 -79
  108. autobyteus/llm/api/groq_llm.py +10 -5
  109. autobyteus/llm/api/mistral_llm.py +13 -8
  110. autobyteus/llm/api/nvidia_llm.py +9 -4
  111. autobyteus/llm/api/ollama_llm.py +58 -50
  112. autobyteus/llm/api/openai_llm.py +20 -14
  113. autobyteus/llm/base_llm.py +95 -34
  114. autobyteus/llm/extensions/base_extension.py +3 -4
  115. autobyteus/llm/extensions/token_usage_tracking_extension.py +13 -4
  116. autobyteus/llm/llm_factory.py +116 -53
  117. autobyteus/llm/models.py +92 -17
  118. autobyteus/llm/ollama_provider.py +6 -2
  119. autobyteus/llm/ollama_provider_resolver.py +44 -0
  120. autobyteus/llm/user_message.py +73 -0
  121. autobyteus/llm/utils/llm_config.py +124 -27
  122. autobyteus/llm/utils/response_types.py +3 -2
  123. autobyteus/llm/utils/token_usage.py +7 -4
  124. autobyteus/rpc/__init__.py +73 -0
  125. autobyteus/rpc/client/__init__.py +17 -0
  126. autobyteus/rpc/client/abstract_client_connection.py +124 -0
  127. autobyteus/rpc/client/client_connection_manager.py +153 -0
  128. autobyteus/rpc/client/sse_client_connection.py +306 -0
  129. autobyteus/rpc/client/stdio_client_connection.py +280 -0
  130. autobyteus/rpc/config/__init__.py +13 -0
  131. autobyteus/rpc/config/agent_server_config.py +153 -0
  132. autobyteus/rpc/config/agent_server_registry.py +152 -0
  133. autobyteus/rpc/hosting.py +244 -0
  134. autobyteus/rpc/protocol.py +244 -0
  135. autobyteus/rpc/server/__init__.py +20 -0
  136. autobyteus/rpc/server/agent_server_endpoint.py +181 -0
  137. autobyteus/rpc/server/base_method_handler.py +40 -0
  138. autobyteus/rpc/server/method_handlers.py +259 -0
  139. autobyteus/rpc/server/sse_server_handler.py +182 -0
  140. autobyteus/rpc/server/stdio_server_handler.py +151 -0
  141. autobyteus/rpc/server_main.py +198 -0
  142. autobyteus/rpc/transport_type.py +13 -0
  143. autobyteus/tools/__init__.py +77 -0
  144. autobyteus/tools/ask_user_input.py +34 -77
  145. autobyteus/tools/base_tool.py +73 -38
  146. autobyteus/tools/bash/__init__.py +2 -0
  147. autobyteus/tools/bash/bash_executor.py +42 -79
  148. autobyteus/tools/browser/__init__.py +2 -0
  149. autobyteus/tools/browser/session_aware/browser_session_aware_navigate_to.py +50 -42
  150. autobyteus/tools/browser/session_aware/browser_session_aware_tool.py +7 -4
  151. autobyteus/tools/browser/session_aware/browser_session_aware_web_element_trigger.py +117 -125
  152. autobyteus/tools/browser/session_aware/browser_session_aware_webpage_reader.py +75 -22
  153. autobyteus/tools/browser/session_aware/browser_session_aware_webpage_screenshot_taker.py +94 -28
  154. autobyteus/tools/browser/session_aware/factory/browser_session_aware_web_element_trigger_factory.py +10 -2
  155. autobyteus/tools/browser/session_aware/factory/browser_session_aware_webpage_reader_factory.py +18 -2
  156. autobyteus/tools/browser/session_aware/factory/browser_session_aware_webpage_screenshot_taker_factory.py +10 -2
  157. autobyteus/tools/browser/session_aware/shared_browser_session_manager.py +4 -3
  158. autobyteus/tools/browser/standalone/__init__.py +7 -0
  159. autobyteus/tools/browser/standalone/factory/google_search_factory.py +17 -2
  160. autobyteus/tools/browser/standalone/factory/webpage_reader_factory.py +17 -2
  161. autobyteus/tools/browser/standalone/factory/webpage_screenshot_taker_factory.py +10 -2
  162. autobyteus/tools/browser/standalone/google_search_ui.py +104 -67
  163. autobyteus/tools/browser/standalone/navigate_to.py +52 -28
  164. autobyteus/tools/browser/standalone/web_page_pdf_generator.py +94 -0
  165. autobyteus/tools/browser/standalone/webpage_image_downloader.py +146 -61
  166. autobyteus/tools/browser/standalone/webpage_reader.py +80 -61
  167. autobyteus/tools/browser/standalone/webpage_screenshot_taker.py +91 -45
  168. autobyteus/tools/factory/__init__.py +9 -0
  169. autobyteus/tools/factory/tool_factory.py +25 -4
  170. autobyteus/tools/file/file_reader.py +22 -51
  171. autobyteus/tools/file/file_writer.py +25 -56
  172. autobyteus/tools/functional_tool.py +249 -0
  173. autobyteus/tools/image_downloader.py +49 -71
  174. autobyteus/tools/mcp/__init__.py +47 -0
  175. autobyteus/tools/mcp/call_handlers/__init__.py +18 -0
  176. autobyteus/tools/mcp/call_handlers/base_handler.py +40 -0
  177. autobyteus/tools/mcp/call_handlers/sse_handler.py +22 -0
  178. autobyteus/tools/mcp/call_handlers/stdio_handler.py +76 -0
  179. autobyteus/tools/mcp/call_handlers/streamable_http_handler.py +55 -0
  180. autobyteus/tools/mcp/config_service.py +237 -0
  181. autobyteus/tools/mcp/factory.py +70 -0
  182. autobyteus/tools/mcp/registrar.py +323 -0
  183. autobyteus/tools/mcp/schema_mapper.py +131 -0
  184. autobyteus/tools/mcp/tool.py +101 -0
  185. autobyteus/tools/mcp/types.py +98 -0
  186. autobyteus/tools/parameter_schema.py +268 -0
  187. autobyteus/tools/pdf_downloader.py +78 -79
  188. autobyteus/tools/registry/__init__.py +0 -2
  189. autobyteus/tools/registry/tool_definition.py +113 -34
  190. autobyteus/tools/registry/tool_registry.py +64 -22
  191. autobyteus/tools/timer.py +150 -102
  192. autobyteus/tools/tool_category.py +11 -0
  193. autobyteus/tools/tool_config.py +117 -0
  194. autobyteus/tools/tool_meta.py +50 -26
  195. autobyteus/tools/tool_state.py +20 -0
  196. autobyteus/tools/usage/__init__.py +6 -0
  197. autobyteus/tools/usage/formatters/__init__.py +31 -0
  198. autobyteus/tools/usage/formatters/anthropic_json_example_formatter.py +18 -0
  199. autobyteus/tools/usage/formatters/anthropic_json_schema_formatter.py +25 -0
  200. autobyteus/tools/usage/formatters/base_formatter.py +42 -0
  201. autobyteus/tools/usage/formatters/default_json_example_formatter.py +42 -0
  202. autobyteus/tools/usage/formatters/default_json_schema_formatter.py +28 -0
  203. autobyteus/tools/usage/formatters/default_xml_example_formatter.py +55 -0
  204. autobyteus/tools/usage/formatters/default_xml_schema_formatter.py +46 -0
  205. autobyteus/tools/usage/formatters/gemini_json_example_formatter.py +34 -0
  206. autobyteus/tools/usage/formatters/gemini_json_schema_formatter.py +25 -0
  207. autobyteus/tools/usage/formatters/google_json_example_formatter.py +34 -0
  208. autobyteus/tools/usage/formatters/google_json_schema_formatter.py +25 -0
  209. autobyteus/tools/usage/formatters/openai_json_example_formatter.py +49 -0
  210. autobyteus/tools/usage/formatters/openai_json_schema_formatter.py +28 -0
  211. autobyteus/tools/usage/parsers/__init__.py +22 -0
  212. autobyteus/tools/usage/parsers/anthropic_xml_tool_usage_parser.py +10 -0
  213. autobyteus/tools/usage/parsers/base_parser.py +41 -0
  214. autobyteus/tools/usage/parsers/default_json_tool_usage_parser.py +106 -0
  215. autobyteus/tools/usage/parsers/default_xml_tool_usage_parser.py +136 -0
  216. autobyteus/tools/usage/parsers/exceptions.py +13 -0
  217. autobyteus/tools/usage/parsers/gemini_json_tool_usage_parser.py +66 -0
  218. autobyteus/tools/usage/parsers/openai_json_tool_usage_parser.py +196 -0
  219. autobyteus/tools/usage/parsers/provider_aware_tool_usage_parser.py +67 -0
  220. autobyteus/tools/usage/providers/__init__.py +22 -0
  221. autobyteus/tools/usage/providers/json_example_provider.py +32 -0
  222. autobyteus/tools/usage/providers/json_schema_provider.py +35 -0
  223. autobyteus/tools/usage/providers/json_tool_usage_parser_provider.py +28 -0
  224. autobyteus/tools/usage/providers/tool_manifest_provider.py +68 -0
  225. autobyteus/tools/usage/providers/xml_example_provider.py +28 -0
  226. autobyteus/tools/usage/providers/xml_schema_provider.py +29 -0
  227. autobyteus/tools/usage/providers/xml_tool_usage_parser_provider.py +26 -0
  228. autobyteus/tools/usage/registries/__init__.py +20 -0
  229. autobyteus/tools/usage/registries/json_example_formatter_registry.py +51 -0
  230. autobyteus/tools/usage/registries/json_schema_formatter_registry.py +51 -0
  231. autobyteus/tools/usage/registries/json_tool_usage_parser_registry.py +42 -0
  232. autobyteus/tools/usage/registries/xml_example_formatter_registry.py +30 -0
  233. autobyteus/tools/usage/registries/xml_schema_formatter_registry.py +33 -0
  234. autobyteus/tools/usage/registries/xml_tool_usage_parser_registry.py +30 -0
  235. {autobyteus-1.0.6.dist-info → autobyteus-1.1.1.dist-info}/METADATA +23 -5
  236. autobyteus-1.1.1.dist-info/RECORD +296 -0
  237. {autobyteus-1.0.6.dist-info → autobyteus-1.1.1.dist-info}/WHEEL +1 -1
  238. autobyteus/agent/async_agent.py +0 -175
  239. autobyteus/agent/async_group_aware_agent.py +0 -136
  240. autobyteus/agent/group/async_group_aware_agent.py +0 -122
  241. autobyteus/agent/group/coordinator_agent.py +0 -36
  242. autobyteus/agent/group/group_aware_agent.py +0 -121
  243. autobyteus/agent/orchestrator/__init__.py +0 -0
  244. autobyteus/agent/orchestrator/base_agent_orchestrator.py +0 -82
  245. autobyteus/agent/orchestrator/multi_replica_agent_orchestrator.py +0 -72
  246. autobyteus/agent/orchestrator/single_replica_agent_orchestrator.py +0 -43
  247. autobyteus/agent/response_parser/__init__.py +0 -0
  248. autobyteus/agent/response_parser/tool_usage_command_parser.py +0 -100
  249. autobyteus/agent/status.py +0 -12
  250. autobyteus/conversation/__init__.py +0 -0
  251. autobyteus/conversation/conversation.py +0 -54
  252. autobyteus/conversation/user_message.py +0 -59
  253. autobyteus/events/decorators.py +0 -29
  254. autobyteus/prompt/prompt_version_manager.py +0 -58
  255. autobyteus/prompt/storage/__init__.py +0 -0
  256. autobyteus/prompt/storage/prompt_version_model.py +0 -29
  257. autobyteus/prompt/storage/prompt_version_repository.py +0 -83
  258. autobyteus/tools/bash/factory/__init__.py +0 -0
  259. autobyteus/tools/bash/factory/bash_executor_factory.py +0 -6
  260. autobyteus/tools/factory/ask_user_input_factory.py +0 -6
  261. autobyteus/tools/factory/image_downloader_factory.py +0 -9
  262. autobyteus/tools/factory/pdf_downloader_factory.py +0 -9
  263. autobyteus/tools/factory/webpage_image_downloader_factory.py +0 -6
  264. autobyteus/tools/file/factory/__init__.py +0 -0
  265. autobyteus/tools/file/factory/file_reader_factory.py +0 -6
  266. autobyteus/tools/file/factory/file_writer_factory.py +0 -6
  267. autobyteus/tools/web_page_pdf_generator.py +0 -90
  268. autobyteus-1.0.6.dist-info/RECORD +0 -157
  269. {autobyteus-1.0.6.dist-info → autobyteus-1.1.1.dist-info}/licenses/LICENSE +0 -0
  270. {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,6 @@
1
+ # file: autobyteus/autobyteus/tools/usage/__init__.py
2
+ """
3
+ This package contains the framework for generating provider-specific
4
+ tool usage information (schemas and examples) and for parsing
5
+ tool usage from LLM responses.
6
+ """
@@ -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__}>"