fix: handle tool descriptions with curly braces in agent interpolation

- Add _interpolate_only helper method to escape curly braces
- Update interpolate_inputs to use new helper
- Add test case for tool descriptions
- Fixes #2145

Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
Devin AI
2025-02-16 05:31:41 +00:00
parent 1b488b6da7
commit be11f9c036
2 changed files with 38 additions and 3 deletions

View File

@@ -1357,6 +1357,32 @@ def test_handle_context_length_exceeds_limit_cli_no():
mock_handle_context.assert_not_called()
def test_interpolate_inputs_with_tool_description():
from crewai.tools import BaseTool
class DummyTool(BaseTool):
name: str = "dummy_tool"
description: str = "Tool Arguments: {'arg': {'description': 'test arg', 'type': 'str'}}"
def _run(self, arg: str) -> str:
"""Run the tool."""
return f"Dummy result for: {arg}"
tool = DummyTool()
agent = Agent(
role="{topic} specialist",
goal="Figure {goal} out",
backstory="I am the master of {role}\nTools: {tool_desc}",
)
agent.interpolate_inputs({
"topic": "AI",
"goal": "life",
"role": "all things",
"tool_desc": tool.description
})
assert "Tool Arguments: {'arg': {'description': 'test arg', 'type': 'str'}}" in agent.backstory
def test_agent_with_all_llm_attributes():
agent = Agent(
role="test role",