forked from lingyuzeng/agent
langgraph adapter
This commit is contained in:
36
langgraph_qwen/prebuilt.py
Normal file
36
langgraph_qwen/prebuilt.py
Normal file
@@ -0,0 +1,36 @@
|
||||
from typing import Any, Dict, Iterable, List, Optional
|
||||
|
||||
from .factory import get_qwen_chat_model, bind_qwen_tools
|
||||
from .validators import validate_tool_names, ToolValidationError
|
||||
|
||||
|
||||
def create_qwen_react_agent(
|
||||
tools: List[Any],
|
||||
*,
|
||||
model: Optional[Any] = None,
|
||||
prefer: str = "custom",
|
||||
tool_choice: Optional[str] = "auto",
|
||||
model_kwargs: Optional[Dict[str, Any]] = None,
|
||||
enforce_tool_name_check: bool = True,
|
||||
**agent_kwargs: Any,
|
||||
):
|
||||
"""
|
||||
Sugar around langgraph.prebuilt.create_react_agent configured for Qwen.
|
||||
|
||||
- If `model` is None, constructs one via get_qwen_chat_model(prefer=..., **model_kwargs).
|
||||
- Binds tools and applies `tool_choice`.
|
||||
- Returns a LangGraph ReAct agent ready to invoke/stream.
|
||||
"""
|
||||
|
||||
from langgraph.prebuilt import create_react_agent as _create
|
||||
|
||||
model_kwargs = model_kwargs or {}
|
||||
|
||||
# Strictly validate tool names before binding, if enabled
|
||||
if enforce_tool_name_check:
|
||||
validate_tool_names(tools, strict=True)
|
||||
if model is None:
|
||||
model = get_qwen_chat_model(prefer=prefer, **model_kwargs)
|
||||
|
||||
model = bind_qwen_tools(model, tools, tool_choice=tool_choice)
|
||||
return _create(model, tools, **agent_kwargs)
|
||||
Reference in New Issue
Block a user