Feature: Custom Code Tool in ToolAgent As a developer, I want to define tools that execute custom Python code from the configuration, so that I can create flexible, dynamic tools without writing new classes. Background: Given a TemplateRenderer is initialized Scenario: Successfully execute a custom code tool Given a configuration for a ToolAgent with a custom code tool that concatenates input with a fixed string """ agents: - name: custom_tool_agent type: tool config: tools: - name: my_custom_tool description: "A custom tool that concatenates." code: | result = f"Custom code executed with: {input_data}" """ And I create the ToolAgent named "custom_tool_agent" When I process this message "my_custom_tool(hello world)" with the agent Then the response should be the following "Custom code executed with: hello world" Scenario: Custom code tool accessing context Given a configuration for a ToolAgent with a custom code tool that accesses context """ agents: - name: context_tool_agent type: tool config: tools: - name: context_reader description: "A custom tool that reads from context." code: | suffix = context.get('suffix', 'default') result = f"{input_data}-{suffix}" """ And I create the ToolAgent named "context_tool_agent" When I process this message "context_reader(data)" with the agent with context """ { "suffix": "from_context" } """ Then the response should be the following "data-from_context" Scenario: Custom code tool with no result assigned Given a configuration for a ToolAgent with a custom code tool that does not assign to result """ agents: - name: no_result_agent type: tool config: tools: - name: no_result_tool description: "A tool that does not assign to result." code: | x = 1 + 1 # Does something but no 'result = ...' """ And I create the ToolAgent named "no_result_agent" When I process this message "no_result_tool(any input)" with the agent Then the response should be the following "" Scenario: Handle execution error in custom code tool Given a configuration for a ToolAgent with a custom code tool containing invalid Python code """ agents: - name: error_agent type: tool config: tools: - name: error_tool description: "A tool with an error." code: | result = 1 / 0 """ And I create the ToolAgent named "error_agent" When I try to process the message "error_tool(trigger)" with the agent Then an ExecutionError should be raised with the message containing "division by zero" Scenario Outline: Handle configuration errors for custom code tool Given a configuration for a ToolAgent with an invalid custom code tool config '' When I try to create the ToolAgent named "bad_config_agent" Then a ConfigurationError should be raised with the message containing "" Examples: | config_json | error_message | | {"agents":[{"name":"bad_config_agent","type":"tool","config":{"tools":[{"description":"d","code":"c"}]}}]} | Each tool configuration must be a dictionary with a 'name' key | | {"agents":[{"name":"bad_config_agent","type":"tool","config":{"tools":[{"name":"t1","description":"d"}]}}]} | is not a built-in tool and is missing a 'code' or 'module' | | {"agents":[{"name":"bad_config_agent","type":"tool","config":{"tools":[{"name":"t1","code":123}]}}]} | is missing 'code' in its configuration or it is not a string |