Skip to content

feat(prebuilt): add text_mode option to create_react_agent#6747

Open
archit0 wants to merge 2 commits intolangchain-ai:mainfrom
archit0:feature/text-mode-react-agent
Open

feat(prebuilt): add text_mode option to create_react_agent#6747
archit0 wants to merge 2 commits intolangchain-ai:mainfrom
archit0:feature/text-mode-react-agent

Conversation

@archit0
Copy link

@archit0 archit0 commented Feb 4, 2026

Summary

  • Adds `text_mode` parameter to `create_react_agent` for models without native tool calling support
  • Implements text-based tool calling using Action/Action Input parsing (ReAct pattern)
  • Allows models like Perplexity Sonar or older LLMs to work with the agent framework

Changes

  • Added `_build_text_mode_prompt()` to generate tool usage instructions
  • Added `_parse_text_tool_call()` to extract Action/Action Input from text responses
  • Added `_convert_text_to_tool_calls()` to convert parsed actions to tool_calls format
  • Added `text_mode` parameter with documentation

Test plan

  • Test with models that don't support native tool calling
  • Verify tool parsing works with various response formats
  • Ensure backward compatibility with existing tool-binding flow

archit0 and others added 2 commits February 4, 2026 15:18
Add a `text_mode` parameter to `create_react_agent` that enables
text-based tool calling instead of native tool binding. This is useful
for models that don't support native tool/function calling APIs.

When `text_mode=True`:
- Tool descriptions are added to the prompt instead of binding tools
- Model responses are parsed for "Action:" and "Action Input:" patterns
- Parsed actions are converted to tool_calls format for execution

This enables models like Perplexity Sonar, older OpenAI models, or
other LLMs without tool calling support to work with the ReAct agent.

Example usage:
```python
from langgraph.prebuilt import create_react_agent

agent = create_react_agent(
    model=my_llm_without_tool_support,
    tools=[my_tool],
    text_mode=True,  # Enable text-based tool calling
)
```

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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.

1 participant