Skip to content

Conversation

@kalanyuz
Copy link
Contributor

Problem

When using functions without type hints as tools in ReAct, the code would throw an error when trying to access arg_types[k] since arg_types would be empty. This made it impossible to use simple functions without type annotations as tools, even for basic operations.

Solution

Modified the tool argument parsing logic to:

  1. First check if the tool has arg_types attribute
  2. Then check if the specific argument key exists in arg_types
  3. Only attempt type validation for arguments that have explicit type hints
  4. Pass through arguments without type hints as-is

Added a test case test_tool_calling_without_typehint that demonstrates:

  • A simple function foo(a, b) without type hints can be used as a tool
  • Arguments are correctly passed through without type validation
  • The tool executes successfully and returns expected results
  • Previous tests, including the ones that uses pydantic args, does not break

@okhat
Copy link
Collaborator

okhat commented Jan 31, 2025

Hey, great catch. Not sure when this regression happened. Will review soon.

@okhat okhat merged commit 71a2a1e into stanfordnlp:main Jan 31, 2025
4 checks passed
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.

2 participants