digmouse’s Ai journey

  • DeepSeek Agent
  • deepseek application
Ai无处不在
专注Ai Agent产品设计开发
  1. 首页
  2. Ai Agent
  3. 正文

Agent model React

27 4 月, 2025 47点热度 0人点赞
import os
from langchain_deepseek import ChatDeepSeek
from langchain_community.tools.tavily_search import TavilySearchResults
from langchain_core.messages import HumanMessage
from langgraph.checkpoint.memory import MemorySaver
from langgraph.prebuilt import create_react_agent

os.environ['DEEPSEEK_API_KEY']='sk-'
os.environ['TAVILY_API_KEY']='tvly-dev-'

## create llm
model=ChatDeepSeek(model='deepseek-chat',temperature=0,streaming=True)

## create search tool
search=TavilySearchResults(max_results=3)
tools=[search]

## create memory
memory=MemorySaver()

## create React agent
agent_executor=create_react_agent(model,tools,checkpointer=memory)

##设置会话配置
config={"configurable":{"thread_id":"example_session"}}

def ask_agent(question):
    for step in agent_executor.stream(
        {"messages":[HumanMessage(content=question)]},
        config=config,
        stream_mode="values",
    ):
        step['messages'][-1].pretty_print()

if __name__=="__main__":
    ask_agent("what is the capital of China?")

 


标签: langchain langgraph
最后更新:27 4 月, 2025

digmouse

这个人很懒,什么都没留下

点赞
< 上一篇
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

Archives

  • 2025 年 5 月
  • 2025 年 4 月
  • 2025 年 3 月
  • 2025 年 2 月
  • 2025 年 1 月

Categories

  • Ai Agent
  • Ai本地知识库
  • Ai资源
  • llamaindex
  • LLM
  • MCP
  • python
  • rerank model
  • Uncategorized

COPYRIGHT © 2025 digmouse’s Ai journey. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang