Skip to content

Conversation

mr-lee
Copy link
Member

@mr-lee mr-lee commented Sep 15, 2025

Edit: replaced with #935

Description

  • Add AgentConfig class for loading configuration from JSON files or dicts
  • Support model, prompt, and tools configuration options
  • Update tool registry to resolve tool names from strands_tools package
  • Maintain backward compatibility with existing Agent constructor
  • Add comprehensive tests for configuration loading and validation

Usage example

For basic usage with the default set of tools available to choose from the config: file_read, editor, http_request, use_agent, and shell

from strands.experimental import AgentConfig

config = AgentConfig({"model": "test-model", "prompt": "Test prompt", "tools": ["file_read", "shell"]})
agent = config.to_agent() # kwargs are passed to the agent init

To configure the set of tools available to the config, you can supply your own tool registry:

from strands import tool
from strands.experimental import AgentConfig
from strands.tools.registry import ToolRegistry

@tool
def add(x: int, y: int) -> int:
    return x + y

tool_registry = ToolRegistry()
tool_registry.process_tools([add])

# Create config with tool selection
config = AgentConfig(
    {"model": "test-model", "prompt": "Test prompt", "tools": ["add"]}, tool_registry=tool_registry
)
agent = config.to_agent() # kwargs are passed to the agent init

You can also load a config from a file:

from strands.experimental import AgentConfig

config = AgentConfig("file://path/to/local/config) # Config gets loaded into dict
agent = config.to_agent() # kwargs are passed to the agent init

Documentation PR

strands-agents/docs#252

Type of Change

New feature

Testing

How have you tested the change? Verify that the changes do not break functionality or introduce warnings in consuming repositories: agents-docs, agents-tools, agents-cli

  • I ran hatch run prepare

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@Unshure
Copy link
Member

Unshure commented Sep 16, 2025

Linking to this issue which requested this feature: #606

@mr-lee mr-lee force-pushed the feature/agent-config-clean branch from 45531dd to f2eadd1 Compare September 23, 2025 22:31
@mr-lee mr-lee force-pushed the feature/agent-config-clean branch from f2eadd1 to a2dad11 Compare September 23, 2025 22:41
@mr-lee mr-lee force-pushed the feature/agent-config-clean branch from 08d8812 to c6712fc Compare September 23, 2025 22:51
@mr-lee mr-lee force-pushed the feature/agent-config-clean branch from 60d35ab to 6b4565a Compare September 23, 2025 23:19
@mr-lee mr-lee force-pushed the feature/agent-config-clean branch from 6b4565a to 763092a Compare September 23, 2025 23:22
@mr-lee mr-lee force-pushed the feature/agent-config-clean branch from dba34ca to 5bc1cd3 Compare September 24, 2025 00:07
@mr-lee mr-lee force-pushed the feature/agent-config-clean branch from d07e18c to e94a5e5 Compare September 24, 2025 00:13
Unshure
Unshure previously approved these changes Sep 26, 2025
mkmeral
mkmeral previously approved these changes Sep 26, 2025
zastrowm
zastrowm previously approved these changes Sep 26, 2025
@Unshure Unshure dismissed stale reviews from zastrowm, mkmeral, and themself via ba9f05c September 26, 2025 14:53
@Unshure Unshure force-pushed the feature/agent-config-clean branch from 47ce51d to ba9f05c Compare September 26, 2025 14:53
zastrowm
zastrowm previously approved these changes Sep 26, 2025
mkmeral
mkmeral previously approved these changes Sep 26, 2025
@Unshure Unshure enabled auto-merge (squash) September 26, 2025 15:43
@Unshure Unshure dismissed stale reviews from mkmeral and zastrowm via 6f44805 September 26, 2025 19:24
mrlee-amazon and others added 7 commits September 26, 2025 15:37
…resolution

- Add AgentConfig class for loading configuration from JSON files or dicts
- Support model, prompt, and tools configuration options
- Update tool registry to resolve tool names from strands_tools package
- Maintain backward compatibility with existing Agent constructor
- Add comprehensive tests for configuration loading and validation
- Fix all linting, type checking, and formatting issues
- Add experimental AgentConfig with to_agent() method for creating Agent instances
- Implement ToolPool for managing collections of tools with clean constructor API
- Support direct tool function passing: ToolPool([calculator, current_time])
- Add ToolPool.from_module() for importing entire tool modules
- Resolve circular import issues with runtime imports (no TYPE_CHECKING needed)
- Add comprehensive test coverage for experimental features
- Clean up obsolete code and maintain backward compatibility
- Remove hacky path manipulation from tests, follow standard import patterns
- Use native Python typing (A | B, list[T], any) instead of typing module
- Require file:// prefix for file paths to maintain standard interface
- Dictionary config only accepts 'prompt' key, not 'system_prompt'
- Rename ToolPool methods: to_agent_tools() -> get_tools(), list_tools() -> list_tool_names()
- Move imports to top of test files following Python conventions
- Add ToolPool integration with tool validation and selection from registry
- Implement static FILE_PREFIX and DEFAULT_TOOLS with proper error handling
- Require either strands_tools installation or custom ToolPool with your own tools
- Remove unnecessary quotes from type hints where imports are available at top
- Organize module constants together for better code structure
- Separate tool pool registry from configured tools with _tool_pool and _configured_tools
- Remove tools parameter from to_agent() - use only configured tools at instantiation
- Fix fallback behavior: no tools specified = no tools (not all tools)
- Add raise_exception_on_missing_tool flag (defaults to True) for graceful degradation
- Apply flag to both default tool loading AND tool validation from ToolPool
- When False, skip missing tools instead of raising errors for robust applications
- Fix examples to properly demonstrate tool selection from registry

🤖 Assisted by Amazon Q Developer
…ve API

- Add AgentConfig class for JSON/dict-based agent configuration
- Add ToolBox class for structured tool management and selection
- Support file:// prefix for JSON config files with validation
- Implement to_agent() method for seamless Agent instantiation
- Add comprehensive tool validation with configurable error handling
- Support both strands_tools integration and custom ToolBox instances
- Include extensive test coverage for all functionality
- Add documentation examples for both dictionary and JSON config formats
- Rename get_tools to list_tools for API consistency
- Clean up import handling with proper TYPE_CHECKING separation
- Consolidate test utilities to reduce code duplication
- Rename all pool variables to toolbox for consistent terminology
- Improve temp file handling in tests with proper cleanup

🤖 Assisted by Amazon Q Developer
- Move toolbox creation before tool validation to enable default toolbox usage
- Add test for loading tools from default toolbox without explicit toolbox parameter
- Mock strands_tools dependencies in tests to avoid external dependencies
- Verify that file_read tool can be loaded from default configuration

🤖 Assisted by Amazon Q Developer
Co-authored-by: Nick Clegg <nac542@gmail.com>
@mr-lee
Copy link
Member Author

mr-lee commented Sep 26, 2025

I'm going to close this in favor of a new one, since the unit tests seem borked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants