Question about LangChain agent example from LangChain Masterclass
Dear I am using the code that you provided for a basic agent (I use gemini llm):
from dotenv import load_dotenv
from langchain import hub
from langchain.agents import (
AgentExecutor,
create_react_agent,
)
from langchain_core.tools import Tool
from langchain_google_genai import ChatGoogleGenerativeAI
# Load environment variables from .env file
load_dotenv()
# Define a very simple tool function that returns the current time
def get_current_time(*args, **kwargs):
"""Returns the current time in H:MM AM/PM format."""
import datetime # Import datetime module to get current time
now = datetime.datetime.now() # Get current time
return now.strftime("%I:%M %p") # Format time in H:MM AM/PM format
# List of tools available to the agent
tools = [
Tool(
name="Time", # Name of the tool
func=get_current_time, # Function that the tool will execute
# Description of the tool
description="Useful for when you need to know the current time",
),
]
# Pull the prompt template from the hub
# ReAct = Reason and Action
prompt = hub.pull("hwchase17/react")
# Initialize a model
llm = ChatGoogleGenerativeAI(
model="gemini-1.5-flash",
temperature=0
)
# Create the ReAct agent using the create_react_agent function
agent = create_react_agent(
llm=llm,
tools=tools,
prompt=prompt,
stop_sequence=True,
)
# Create an agent executor from the agent and tools
agent_executor = AgentExecutor.from_agent_and_tools(
agent=agent,
tools=tools,
verbose=True,
max_iterations=1
)
# Run the agent with a test query
response = agent_executor.invoke({"input": "What time is it?"})
# Print the response from the agent
print("response:", response)
However, the result that I get is the following:
> Entering new AgentExecutor chain...
Thought: I need to get the current time. I can use the Time function for that.
Action: Time
Action Input: ()11:13 AM
response: {'input': 'What time is it?', 'output': 'Agent stopped due to iteration limit or time limit.'}
What could e the cause of the problem?
0
0 comments
Denis Vasiliev
1
Question about LangChain agent example from LangChain Masterclass
AI Developer Accelerator
skool.com/ai-developer-accelerator
Master AI & software development to build apps and unlock new income streams. Transform ideas into profits. 💡➕🤖➕👨‍💻🟰💰
Leaderboard (30-day)
Powered by