Skip to content

How to deal with agents not calling the appropriate tools #178

Open
@roaguirre

Description

@roaguirre

Question

I'm building agents that run within Github actions (repo).

I have the problem that the agents do not always call the appropriate tools, even when the instructions request them to do so.

Here's an example:

class PRReviewResponse(BaseModel):
    """Response model for PR Review agent."""

    summary: str = Field(description="A summary of the changes in the PR")
    code_quality: str = Field(description="Assessment of code quality")
    issues: List[str] = Field(description="List of potential issues or bugs found")
    suggestions: List[str] = Field(description="List of suggestions for improvement")
    assessment: str = Field(
        description="Overall assessment (approve, request changes, comment)"
    )
    review_event: PRReviewEvent = Field(
        description="The review event type to use for the PR review"
    )

instructions = """
  You are a reviewer who helps analyze GitHub pull requests.

  Your task is to use the tools provided to review the PR files, analyze the code changes, and provide:
  1. A summary of the changes
  2. Code quality assessment
  3. Potential issues or bugs
  4. Suggestions for improvement
  5. Overall assessment (APPROVE, REQUEST_CHANGES, COMMENT)

  Always provide constructive feedback with specific examples and suggestions.

  IMPORTANT (Follow these steps in order):
  1. You MUST use the get_pull_request tool to get information about the PR.
  2. You MUST use the get_pull_request_files tool to fetch the diff of the files in the PR.
  3. You can use the get_repository_file_content tool to get more context about the files in the PR.
  4. You can use the search_code tool to search for code in the repository.
  5. You MUST call the create_pull_request_review tool to submit your review.
  """

tools = [
    get_pull_request,
    get_pull_request_files,
    get_repository_info,
    get_repository_file_content,
    search_code,
    create_pull_request_review,
]

agent = Agent(
        name="PR Review Agent",
        instructions=instructions,
        tools=tools,
        model=model,
        output_type=PRReviewResponse,
    )

There are instances where the agent only runs the create_pull_request_review tool and hallucinates the PR changes (I'm using o3-mini).

Any suggestions?

I had success by removing the specific tools from the agent, running them manually, and providing the tool response as part of the input message. Still, I'd prefer if the agent were to follow the instructions.

When the tools are wrapped with the @function_tool decorator we can only get a string response from the original function (when calling FunctionTool.on_invoke_tool), so this workaround is still odd

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionQuestion about using the SDK

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions