Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] program doesn't know how to use tools (ReAct) #7903

Open
chrico-bu-uab opened this issue Mar 4, 2025 · 3 comments
Open

[Bug] program doesn't know how to use tools (ReAct) #7903

chrico-bu-uab opened this issue Mar 4, 2025 · 3 comments
Labels
bug Something isn't working

Comments

@chrico-bu-uab
Copy link

What happened?

(See "Steps to reproduce" for code.)

When I compile/save my program, I see stuff like this:

        "trajectory": "[[ ## thought_0 ## ]]\nI need to determine the margin status of the breast cancer pathology report.\n\n[[ ## tool_name_0 ## ]]\nRegex\n\n[[ ## tool_args_0 ## ]]\n{}\n\n[[ ## observation_0 ## ]]\nFailed to execute: Regex.__call__() missing 1 required positional argument: 'report'\n\n[[ ## thought_1 ## ]]\nI need to determine the margin status of the breast cancer pathology report.\n\n[[ ## tool_name_1 ## ]]\nRegex\n\n[[ ## tool_args_1 ## ]]\n{}\n\n[[ ## observation_1 ## ]]\nFailed to execute: Regex.__call__() missing 1 required positional argument: 'report'\n\n[[ ## thought_2 ## ]]\nI need to determine the margin status of the breast cancer pathology report.\n\n[[ ## tool_name_2 ## ]]\nRegex\n\n[[ ## tool_args_2 ## ]]\n{}\n\n[[ ## observation_2 ## ]]\nFailed to execute: Regex.__call__() missing 1 required positional argument: 'report'\n\n[[ ## thought_3 ## ]]\nI need to determine the margin status of the breast cancer pathology report.\n\n[[ ## tool_name_3 ## ]]\nRegex\n\n[[ ## tool_args_3 ## ]]\n{}\n\n[[ ## observation_3 ## ]]\nFailed to execute: Regex.__call__() missing 1 required positional argument: 'report'\n\n[[ ## thought_4 ## ]]\nI need to determine the margin status of the breast cancer pathology report.\n\n[[ ## tool_name_4 ## ]]\nRegex\n\n[[ ## tool_args_4 ## ]]\n{}\n\n[[ ## observation_4 ## ]]\nFailed to execute: Regex.__call__() missing 1 required positional argument: 'report'",

Not sure if I am doing something wrong or if there is a bug. The documentation is very unclear about the args parameter in particular.

Thanks!

Steps to reproduce

I can't provide the data, but below is the tool function.

class Regex:
    """Simple tool that uses regular expressions to extract margin status."""

    name = "Regex"
    desc = "extracts margin status using regular expressions"
    args = {'report': {'type': 'string', 'description': 'text from a pathology report'}}

    def __init__(self):
        self.pattern = re.compile(r"positive margin|margin positive|negative margin|margin negative")

    def __call__(self, report: str) -> str:
        """Extract margin status from the report."""
        match = "|".join(self.pattern.findall(report.lower()))
        print("Match:", match)
        if match:
            return "positive" if "positive" in match else "negative"
        return "inconclusive"

DSPy version

2.6.9rc1

@chrico-bu-uab chrico-bu-uab added the bug Something isn't working label Mar 4, 2025
@okhat
Copy link
Collaborator

okhat commented Mar 4, 2025

Hey @chrico-bu-uab ! What model are you using?

With 4o-mini, I run this and it works fine:

import re

pattern = re.compile(r"positive margin|margin positive|negative margin|margin negative")

def regex(report: str) -> str:
    """Extract margin status using regular expressions."""
    match = "|".join(pattern.findall(report.lower()))
    if match:
        return "positive" if "positive" in match else "negative"
    return "inconclusive"


r = dspy.ReAct('question -> answer', tools=[regex])
r(question="positive margin")

@chrico-bu-uab
Copy link
Author

chrico-bu-uab commented Mar 5, 2025 via email

@okhat
Copy link
Collaborator

okhat commented Mar 5, 2025

I see. I'd avoid reasoning models for non-reasoning problems; they're known to, at least so far, be overfit to specific types of problems (math, coding) and less good at following arbitrary instructions.

You could use LLama-3.2-3B or 3.1-8B for instance. Or Qwen-2.5 models.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants