LAP个人助理
使用LangGraph构建的多代理个人助理系统,通过对话式AI管理日历事件和YouTrack问题。
安装和设置
先决条件
- Python 3.13+
- 紫外线 包管理器
使用uv进行安装
# Clone the repository
git clone
cd LAP_PersonalAssistant
# Install dependencies
uv sync
# Set up environment variables
chmod +x set_env.sh
./set_env.sh配置
- 将您的API凭据添加到
secrets/目录:
- anthropic_token.txt -无烟煤API键 - yt_token.txt -YouTrack代币 - credentials.json -谷歌日历凭据 - token.json -谷歌日历令牌
运行应用程序
# Activate virtual environment and run
uv run python main_business.pyLangGraph利用率
该项目利用 LangGraph 创建分层多代理系统:
建筑
- 主要主管:将用户请求路由到适当的专业代理
- 代理节点:个人代理(日历管理器、YouTrack管理器)处理特定任务
- 状态管理:共享
AgentState跟踪对话流和代理输出
使用的关键LangGraph功能
StateGraph:管理代理工作流和状态转换create_react_agent:创建具有工具访问权限的ReAct模式代理InMemorySaver:提供对话检查点- 动态代理路由的条件边
工作流程
- 用户输入→ 主要主管
- 基于LLM的代理选择
- 专业代理执行
- 工具调用(日历/YouTrack API)
- 响应聚合
添加新代理
1.创建代理文件
创建 agents/new_agent_manager.py:
from langgraph.prebuilt import create_react_agent
from langchain_aws import ChatBedrock
from agent_state import AgentState
from tools.base_tools import BASE_TOOLS
def conversational_new_agent(state: AgentState):
print("NEW AGENT: Hello, I'm the New Agent")
# Load prompt
with open("prompts/new_agent_prompt.txt", 'r') as f:
prompt = f.read().strip()
# Configure LLM
llm = ChatBedrock(
model_id="eu.anthropic.claude-3-7-sonnet-20250219-v1:0",
model_kwargs={"temperature": 0}
)
# Add agent-specific tools
tools = [your_custom_tools] + BASE_TOOLS
# Create agent
agent = create_react_agent(llm, tools, prompt)
# Conversation loop
while True:
request = input("YOU: ").strip()
if request.lower() in ['exit', 'quit', 'bye']:
break
response = agent.invoke({"messages": [{"role": "user", "content": request}]})
print("NEW AGENT:", response["messages"][-1].content)2.创建代理提示
添加 prompts/new_agent_prompt.txt 根据代理人的具体指示。
3.更新主主管
在……里面 main_business.py:
# Import new agent
from agents.new_agent_manager import conversational_new_agent
# Add to supervisor prompt
"- NewAgentManager: for new agent tasks"
# Add to valid teams
valid_teams = ["YoutrackManager", "CalendarManager", "NewAgentManager"]
# Add node to graph
main_workflow.add_node("new_agent_node", conversational_new_agent)
# Add routing
"NewAgentManager": "new_agent_node"
# Add edge
main_workflow.add_edge("new_agent_node", END)4.创建自定义工具(可选)
在中添加工具 tools/new_agent_tools.py 遵循现有模式。
项目结构
LAP_PersonalAssistant/
├── agents/ # Agent implementations
├── tools/ # Tool definitions
├── prompts/ # Agent prompts
├── utils/ # Utility functions
├── secrets/ # API credentials
├── main_business.py # Main application
└── agent_state.py # Shared state definition