Spaces:
Runtime error
Runtime error
Commit ·
3fd974b
1
Parent(s): 49ce5e8
fix: updated agent base
Browse files- pmcp/agents/agent_base.py +12 -5
pmcp/agents/agent_base.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import logging
|
| 2 |
from typing import List, TypeVar, Optional
|
| 3 |
|
| 4 |
-
from langchain_core.messages import AnyMessage, BaseMessage
|
| 5 |
from pydantic import BaseModel
|
| 6 |
from langchain_core.tools import BaseTool
|
| 7 |
from langchain_openai import ChatOpenAI
|
|
@@ -29,14 +29,21 @@ class AgentBlueprint:
|
|
| 29 |
self.tools = {tool.name: tool for tool in tools}
|
| 30 |
self.logger = logging.getLogger(self.__class__.__name__)
|
| 31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
def call_agent(self, messages: List[AnyMessage]) -> BaseMessage:
|
| 33 |
-
response = self.llm.with_retry(stop_after_attempt=2).invoke(
|
|
|
|
|
|
|
| 34 |
response.name = self.agent_name
|
| 35 |
return response
|
| 36 |
|
| 37 |
async def acall_agent(self, messages: List[AnyMessage]) -> BaseMessage:
|
| 38 |
response = await self.llm.with_retry(stop_after_attempt=2).ainvoke(
|
| 39 |
-
input=messages
|
| 40 |
)
|
| 41 |
response.name = self.agent_name
|
| 42 |
return response
|
|
@@ -47,7 +54,7 @@ class AgentBlueprint:
|
|
| 47 |
response = (
|
| 48 |
self.llm.with_structured_output(clazz)
|
| 49 |
.with_retry(stop_after_attempt=2)
|
| 50 |
-
.invoke(input=messages)
|
| 51 |
)
|
| 52 |
|
| 53 |
return response
|
|
@@ -58,7 +65,7 @@ class AgentBlueprint:
|
|
| 58 |
response = (
|
| 59 |
await self.llm.with_structured_output(clazz)
|
| 60 |
.with_retry(stop_after_attempt=2)
|
| 61 |
-
.ainvoke(input=messages)
|
| 62 |
)
|
| 63 |
|
| 64 |
return response
|
|
|
|
| 1 |
import logging
|
| 2 |
from typing import List, TypeVar, Optional
|
| 3 |
|
| 4 |
+
from langchain_core.messages import AnyMessage, BaseMessage, SystemMessage
|
| 5 |
from pydantic import BaseModel
|
| 6 |
from langchain_core.tools import BaseTool
|
| 7 |
from langchain_openai import ChatOpenAI
|
|
|
|
| 29 |
self.tools = {tool.name: tool for tool in tools}
|
| 30 |
self.logger = logging.getLogger(self.__class__.__name__)
|
| 31 |
|
| 32 |
+
def __set_system_prompt(self, messages: List[AnyMessage]):
|
| 33 |
+
if self.system_prompt:
|
| 34 |
+
return [SystemMessage(content=self.system_prompt)] + messages
|
| 35 |
+
return messages
|
| 36 |
+
|
| 37 |
def call_agent(self, messages: List[AnyMessage]) -> BaseMessage:
|
| 38 |
+
response = self.llm.with_retry(stop_after_attempt=2).invoke(
|
| 39 |
+
input=self.__set_system_prompt(messages)
|
| 40 |
+
)
|
| 41 |
response.name = self.agent_name
|
| 42 |
return response
|
| 43 |
|
| 44 |
async def acall_agent(self, messages: List[AnyMessage]) -> BaseMessage:
|
| 45 |
response = await self.llm.with_retry(stop_after_attempt=2).ainvoke(
|
| 46 |
+
input=self.__set_system_prompt(messages)
|
| 47 |
)
|
| 48 |
response.name = self.agent_name
|
| 49 |
return response
|
|
|
|
| 54 |
response = (
|
| 55 |
self.llm.with_structured_output(clazz)
|
| 56 |
.with_retry(stop_after_attempt=2)
|
| 57 |
+
.invoke(input=self.__set_system_prompt(messages))
|
| 58 |
)
|
| 59 |
|
| 60 |
return response
|
|
|
|
| 65 |
response = (
|
| 66 |
await self.llm.with_structured_output(clazz)
|
| 67 |
.with_retry(stop_after_attempt=2)
|
| 68 |
+
.ainvoke(input=self.__set_system_prompt(messages))
|
| 69 |
)
|
| 70 |
|
| 71 |
return response
|