forked from lingyuzeng/agent
44 lines
978 B
Python
44 lines
978 B
Python
"""
|
||
Example using the sugar: create_qwen_react_agent(...)
|
||
|
||
Prereqs:
|
||
uv pip install -e '.[openai,custom]'
|
||
|
||
Env:
|
||
export QWEN_API_KEY=sk-...
|
||
export QWEN_BASE_URL=https://dashscope-intl.aliyuncs.com/compatible-mode/v1
|
||
export QWEN_MODEL=qwen3-coder-flash
|
||
"""
|
||
|
||
from langchain_core.messages import HumanMessage
|
||
|
||
try:
|
||
from langchain.tools import tool
|
||
except Exception:
|
||
from langchain_core.tools import tool # type: ignore
|
||
|
||
from langgraph_qwen import create_qwen_react_agent
|
||
|
||
|
||
@tool
|
||
def echo(text: str) -> str:
|
||
"""Echo back the given text."""
|
||
return text
|
||
|
||
|
||
def main():
|
||
agent = create_qwen_react_agent(
|
||
[echo],
|
||
prefer="custom", # use our custom BaseChatModel by default
|
||
model_kwargs={"temperature": 0},
|
||
)
|
||
|
||
res = agent.invoke({"messages": [HumanMessage(content="调用 echo 工具返回:你好,LangGraph!")]})
|
||
print("\n=== Final ===\n")
|
||
print(res["messages"][-1].content)
|
||
|
||
|
||
if __name__ == "__main__":
|
||
main()
|
||
|