Commit
·
9893f68
1
Parent(s):
92957f7
add: github integration with mcp server
Browse files- main.py +18 -7
- pmcp/agents/pm_agent.py +36 -0
- pmcp/agents/trello_agent.py +5 -5
main.py
CHANGED
|
@@ -9,7 +9,7 @@ from langgraph.graph import MessagesState, END, StateGraph
|
|
| 9 |
from langchain_core.messages import HumanMessage
|
| 10 |
from langgraph.checkpoint.memory import MemorySaver
|
| 11 |
|
| 12 |
-
from pmcp.agents.
|
| 13 |
|
| 14 |
|
| 15 |
async def call_llm(llm_with_tools: ChatOpenAI, state: MessagesState):
|
|
@@ -18,7 +18,7 @@ async def call_llm(llm_with_tools: ChatOpenAI, state: MessagesState):
|
|
| 18 |
|
| 19 |
|
| 20 |
async def main():
|
| 21 |
-
|
| 22 |
{
|
| 23 |
"trello": {
|
| 24 |
"url": "http://localhost:8000/sse",
|
|
@@ -27,10 +27,21 @@ async def main():
|
|
| 27 |
}
|
| 28 |
)
|
| 29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
memory = MemorySaver()
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
| 34 |
llm = ChatOpenAI(
|
| 35 |
model="meta-llama/Meta-Llama-3.1-8B-Instruct",
|
| 36 |
temperature=0.0,
|
|
@@ -38,14 +49,14 @@ async def main():
|
|
| 38 |
base_url="https://api.studio.nebius.com/v1/",
|
| 39 |
)
|
| 40 |
|
| 41 |
-
trello_agent =
|
| 42 |
-
tools=
|
| 43 |
llm=llm,
|
| 44 |
)
|
| 45 |
|
| 46 |
graph = StateGraph(MessagesState)
|
| 47 |
|
| 48 |
-
graph.add_node("llm", trello_agent.
|
| 49 |
graph.add_node("tool", tool_node)
|
| 50 |
graph.set_entry_point("llm")
|
| 51 |
|
|
|
|
| 9 |
from langchain_core.messages import HumanMessage
|
| 10 |
from langgraph.checkpoint.memory import MemorySaver
|
| 11 |
|
| 12 |
+
from pmcp.agents.pm_agent import ProjectManagerAgent
|
| 13 |
|
| 14 |
|
| 15 |
async def call_llm(llm_with_tools: ChatOpenAI, state: MessagesState):
|
|
|
|
| 18 |
|
| 19 |
|
| 20 |
async def main():
|
| 21 |
+
mcp_client_trello = MultiServerMCPClient(
|
| 22 |
{
|
| 23 |
"trello": {
|
| 24 |
"url": "http://localhost:8000/sse",
|
|
|
|
| 27 |
}
|
| 28 |
)
|
| 29 |
|
| 30 |
+
mcp_client_github = MultiServerMCPClient(
|
| 31 |
+
{
|
| 32 |
+
"github": {
|
| 33 |
+
"url": "https://callecaje-git-repo-explorer.hf.space/gradio_api/mcp/sse",
|
| 34 |
+
"transport": "sse",
|
| 35 |
+
}
|
| 36 |
+
}
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
memory = MemorySaver()
|
| 40 |
|
| 41 |
+
trello_tools = await mcp_client_trello.get_tools()
|
| 42 |
+
github_tools = await mcp_client_github.get_tools()
|
| 43 |
+
tool_node = ToolNode(github_tools + trello_tools)
|
| 44 |
+
|
| 45 |
llm = ChatOpenAI(
|
| 46 |
model="meta-llama/Meta-Llama-3.1-8B-Instruct",
|
| 47 |
temperature=0.0,
|
|
|
|
| 49 |
base_url="https://api.studio.nebius.com/v1/",
|
| 50 |
)
|
| 51 |
|
| 52 |
+
trello_agent = ProjectManagerAgent(
|
| 53 |
+
tools=github_tools + trello_tools,
|
| 54 |
llm=llm,
|
| 55 |
)
|
| 56 |
|
| 57 |
graph = StateGraph(MessagesState)
|
| 58 |
|
| 59 |
+
graph.add_node("llm", trello_agent.acall_pm_agent)
|
| 60 |
graph.add_node("tool", tool_node)
|
| 61 |
graph.set_entry_point("llm")
|
| 62 |
|
pmcp/agents/pm_agent.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import List
|
| 2 |
+
|
| 3 |
+
from pmcp.agents.agent_base import AgentBlueprint
|
| 4 |
+
from langchain_core.tools import BaseTool
|
| 5 |
+
from langchain_core.messages import SystemMessage
|
| 6 |
+
from langchain_openai import ChatOpenAI
|
| 7 |
+
from langgraph.graph import MessagesState
|
| 8 |
+
|
| 9 |
+
SYSTEM_PROMPT = """
|
| 10 |
+
You are an assistant that can manage Trello boards and projects and also look at github in order to add info on some trello cards.
|
| 11 |
+
You will be given a set of tools to work with. Each time you decide to use a tool that modifies in any way a Trello board, you MUST ask the user if wants to proceed.
|
| 12 |
+
If the user's answer is negative, then you have to abort everything and end the conversation.
|
| 13 |
+
"""
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
class ProjectManagerAgent:
|
| 17 |
+
def __init__(self, tools: List[BaseTool], llm: ChatOpenAI):
|
| 18 |
+
self.agent = AgentBlueprint(
|
| 19 |
+
agent_name="PM_AGENT",
|
| 20 |
+
description="The agent that performs actions on Trello and Github",
|
| 21 |
+
tools=tools,
|
| 22 |
+
system_prompt=SYSTEM_PROMPT.strip(),
|
| 23 |
+
llm=llm,
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
def call_pm_agent(self, state: MessagesState):
|
| 27 |
+
response = self.agent.call_agent(
|
| 28 |
+
[SystemMessage(content=self.agent.system_prompt)] + state.get("messages")
|
| 29 |
+
)
|
| 30 |
+
return {"messages": [response]}
|
| 31 |
+
|
| 32 |
+
async def acall_pm_agent(self, state: MessagesState):
|
| 33 |
+
response = await self.agent.acall_agent(
|
| 34 |
+
[SystemMessage(content=self.agent.system_prompt)] + state.get("messages")
|
| 35 |
+
)
|
| 36 |
+
return {"messages": [response]}
|
pmcp/agents/trello_agent.py
CHANGED
|
@@ -15,7 +15,7 @@ If the user's answer is negative, then you have to abort everything and end the
|
|
| 15 |
|
| 16 |
class TrelloAgent:
|
| 17 |
def __init__(self, tools: List[BaseTool], llm: ChatOpenAI):
|
| 18 |
-
self.
|
| 19 |
agent_name="TRELLO_AGENT",
|
| 20 |
description="The agent that performs actions on Trello",
|
| 21 |
tools=tools,
|
|
@@ -24,13 +24,13 @@ class TrelloAgent:
|
|
| 24 |
)
|
| 25 |
|
| 26 |
def call_trello_agent(self, state: MessagesState):
|
| 27 |
-
response = self.
|
| 28 |
-
[SystemMessage(content=self.
|
| 29 |
)
|
| 30 |
return {"messages": [response]}
|
| 31 |
|
| 32 |
async def acall_trello_agent(self, state: MessagesState):
|
| 33 |
-
response = await self.
|
| 34 |
-
[SystemMessage(content=self.
|
| 35 |
)
|
| 36 |
return {"messages": [response]}
|
|
|
|
| 15 |
|
| 16 |
class TrelloAgent:
|
| 17 |
def __init__(self, tools: List[BaseTool], llm: ChatOpenAI):
|
| 18 |
+
self.agent = AgentBlueprint(
|
| 19 |
agent_name="TRELLO_AGENT",
|
| 20 |
description="The agent that performs actions on Trello",
|
| 21 |
tools=tools,
|
|
|
|
| 24 |
)
|
| 25 |
|
| 26 |
def call_trello_agent(self, state: MessagesState):
|
| 27 |
+
response = self.agent.call_agent(
|
| 28 |
+
[SystemMessage(content=self.agent.system_prompt)] + state.get("messages")
|
| 29 |
)
|
| 30 |
return {"messages": [response]}
|
| 31 |
|
| 32 |
async def acall_trello_agent(self, state: MessagesState):
|
| 33 |
+
response = await self.agent.acall_agent(
|
| 34 |
+
[SystemMessage(content=self.agent.system_prompt)] + state.get("messages")
|
| 35 |
)
|
| 36 |
return {"messages": [response]}
|