dspy
dspy copied to clipboard
AvaTaR agent: 'Action' object has no attribute 'strip'
(dspy-ai 2.5.0)
Hi dspy-team, I am getting the following error after upgrading dspy-ai to 2.5.0 when using the AvatarOptimizer.
Starting the task... Processing examples: 14%|█▍ | 1/7 [00:01<00:06, 1.09s/it] 'Action' object has no attribute 'strip'
from dspy.teleprompt import AvatarOptimizer
avatar = Avatar(
tools=tools,
signature=LogRootifyReasoner,
verbose=True,
max_iters=6,
)
optimizer = AvatarOptimizer(
metric=metric,
max_iters=2,
lower_bound=0.6,
upper_bound=0.7,
max_negative_inputs=10,
max_positive_inputs=10,
)
optimized_avatar = optimizer.compile(
student=avatar,
trainset=trainset
)
Iteration 1/2 Starting the task... Starting the task... Starting the task... Starting the task... Starting the task... Starting the task... Starting the task... Processing examples: 14%|█▍ | 1/7 [00:01<00:06, 1.09s/it] 'Action' object has no attribute 'strip' 'Action' object has no attribute 'strip' 'Action' object has no attribute 'strip' 'Action' object has no attribute 'strip' 'Action' object has no attribute 'strip' Processing examples: 100%|██████████| 7/7 [00:02<00:00, 3.44it/s] 'Action' object has no attribute 'strip' 'Action' object has no attribute 'strip' Average Score: 0.0
The code is attempting to call the strip() method on an Action object, which doesn't have this method. The error happens when the DSPy framework processes the action_1 output field in signatures.py. The framework expects the output to be a string (possibly a JSON string), but it receives an Action object instead. Action doesn't have a strip() method.
dspy/predict$ less avatar/signatures.py:
import dspy
from dspy.predict.avatar.models import Action
class Actor(dspy.Signature):
"""You will be given `Tools` which will be a list of tools to use to accomplish the `Goal`. Given the user query, your task is to decide which tool to use and what input values to provide.
You will output action needed to accomplish the `Goal`. `Action` should have a tool to use and the input query to pass to the tool.
Note: You can opt to use no tools and provide the final answer directly. You can also one tool multiple times with different input queries if applicable."""
goal: str = dspy.InputField(
prefix="Goal:",
desc="Task to be accomplished.",
)
tools: list[str] = dspy.InputField(
prefix="Tools:",
desc="list of tools to use",
)
action_1: Action = dspy.OutputField(
prefix="Action 1:",
desc="1st action to take.",
)
dspy/predict/avatar/models.py:
class Action(BaseModel):
tool_name: Any = Field(..., description="Name of the tool to use.")
tool_input_query: Any = Field(..., description="Query to pass as input to the tool.")