Spaces:
Paused
Paused
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 | |
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) | |