unknown_tool_handler_example

command
v0.0.0-...-f13f4f7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 29, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

README

Unknown Tools Handler for ReAct Agent

  • Demonstrates UnknownToolsHandler in compose.ToolsNodeConfig when the model emits an unknown tool call.
  • Mock ChatModel produces three turns: unknown tool call → correct tool call → final answer.
  • Builds on the ReAct agent from the flow package.

Rationale

  • ReAct agents often rely on the model to select tool names from a provided list. In practice, models may hallucinate a tool name not registered with the ToolsNode.
  • Instead of aborting the agent on such an error, the UnknownToolsHandler produces a clear, structured message that is fed back to the ChatModel as the tool result.
  • This feedback informs the model that the tool name is invalid and encourages it to pick a valid tool in the next turn, improving robustness and convergence.
  • The example shows: first turn emits an unknown tool call; the handler returns guidance; the second turn uses the correct tool; the final turn produces the answer.

Run

  • cd flow/agent/react/unknown_tool_handler_example
  • go run main.go

Expected

  • Prints a handler message for the unknown tool name.
  • Executes the sum tool on the second turn and returns {"sum":3}.
  • Outputs the final assistant answer 3.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL