本地Ollama+Agent+LangGraph+LangSmith运行

基于LangChain官网的例子,自己本地搭建了一套智能体应用,结合本地Ollama部署模型,实现工作流+智能体交互。

官网:https://docs.langchain.com/

代码:

agent.py

复制代码
from langchain.agents import create_agent
from langchain.chat_models import init_chat_model

def send_email(to: str, subject: str, body: str):
    """Send an email"""
    email = {
        "to": to,
        "subject": subject,
        "body": body
    }
    # ... email sending logic

    return f"Email sent to {to}"

# 先初始化模型
model = init_chat_model(
    model="ollama:llama3.2:1b",
    base_url="http://127.0.0.1:11434",
)

# 然后创建智能体
agent = create_agent(
    model=model,
    tools=[send_email],
    system_prompt="You are an email assistant. Always use the send_email tool.",
)

.env

复制代码
LANGSMITH_API_KEY=lsv2...

langgraph.json

复制代码
{
  "dependencies": ["."],
  "graphs": {
    "agent": "./agent/agent.py:agent"
  },
  "env": ".env"
}

目录结构如官网所示

复制代码
my-app/
├── src
│   └── agent.py
├── .env
└── langgraph.json

安装好必要的程序包,参考官网,启动项目

复制代码
python -m langgraph_cli dev

启动后

浏览器访问:https://smith.langchain.com/studio/?baseUrl=http://127.0.0.1:2024

页面如下

注册账户后页面如下,多一些功能

git下载前端会话页面源码并安装依赖启动:

复制代码
# Clone the repository
git clone https://github.com/langchain-ai/agent-chat-ui.git
cd agent-chat-ui

# Install dependencies and start
pnpm install
pnpm dev

启动后,浏览器访问:http://localhost:3000/

填写配置

URL

复制代码
http://127.0.0.1:2024

Graph ID

复制代码
agent

API Key就是.env配置的

复制代码
lsv2...

点击Continue按钮,页面如下

发送hello测试

官网例子就跑通了!

相关推荐
陳陈陳2 小时前
从“胡说八道”到“妙笔生花”:我用LangChain手搓了一个可控AI写作流(Temperature+TopK调参指南)
langchain·llm
糖果店的幽灵2 小时前
【DeepAgents 从入门到精通】Context Management 上下文管理
java·人工智能·后端·spring·中间件·langgraph·deepagents
小林ixn2 小时前
大模型随机说话的秘密:Temperature 和 Top K 深度解析,LangChain 实战调优
人工智能·langchain
想会飞的蒲公英3 小时前
计算机怎样读取中文文本:编码、清洗与标准化
人工智能·python·自然语言处理
SeaTunnel4 小时前
从 Python Script 地狱到标准化数据集成框架
大数据·开发语言·python·程序员·代码·seatunnel
深度研习笔记4 小时前
OpenCV工业视觉实战09|项目EXE打包+工控机无环境部署+后台常驻运行,彻底脱离Python环境,完成项目最终交付
python·opencv·webpack
CCPC不拿奖不改名5 小时前
大模型推理架构与开源生态知识整理
数据库·windows·python·架构·langchain·开源·github
Marst Code5 小时前
(python)2026Plotly 库评估:交互式可视化到底值不值得引入?
开发语言·python
databook5 小时前
当散点图不够用时:用 t-SNE 可视化多维数据
python·数据分析·数据可视化
Darling噜啦啦7 小时前
揭秘 LLM 的随机性黑盒:从 Temperature + Top-K 到 LangChain Chain 工作流实战
langchain·llm