File size: 1,649 Bytes
9c9a39f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from langchain.agents import AgentExecutor, Agent, create_openai_tools_agent
from langchain_core.prompts import PromptTemplate, ChatPromptTemplate, MessagesPlaceholder
from langchain_core.tools import tool
from langchain_openai import ChatOpenAI
#from tools.robot_information import robot_information
from langchain.agents import create_tool_calling_agent
from langchain.agents import AgentExecutor, ZeroShotAgent
from langchain_core.tools import tool
import json

@tool
def robot_information(project_name: str) -> str:
    """Retrieves count and detailed information about the robots in the named project in real-time in JSON format"""
    print("retrieved robot")
    data = {
        "count": 2,
        "information": [
            {"name": "Robot1", "battery": 90, "type": "heavy"},
            {"name": "Robot2", "battery": 34, "type": "medium"}
        ]
    }
    return json.dumps(data)
class ProjectAgent(AgentExecutor):
    
    def __init__(self, llm, system_prompt):
        prompt = ChatPromptTemplate.from_messages(
            [
               
                MessagesPlaceholder(variable_name="messages"),
                MessagesPlaceholder(variable_name="agent_scratchpad"),
            ]
        )
        #agent = prompt | llm
        tools = [robot_information] 
        #llm_with_tools = llm.bind_tools(tools)
       # agent = create_openai_tools_agent(llm, [robot_information], prompt)
        agent = create_tool_calling_agent(llm, tools, prompt)
       
        #agent = prompt | llm_with_tools
        super().__init__(agent=agent, tools=[robot_information], verbose=True)