I've created a simple agent using Langchain and I just want to print out the last bit, is there an easy way to do this. (I mean everything that comes after AI);
Test code
from langchain.agents import Tool
import os
from langchain.agents import AgentType
from langchain.memory import ConversationBufferMemory
from langchain import OpenAI
from langchain.utilities import GoogleSerperAPIWrapper
from langchain.agents import initialize_agent
os.environ["SERPER_API_KEY"] = ""
os.environ["OPENAI_API_KEY"] = ""
search = GoogleSerperAPIWrapper()
tools = [
Tool(
name = "Current Search",
func=search.run,
description="useful for when you need to answer questions about current events or the current state of the world"
),
]
memory = ConversationBufferMemory (memory_key="chat_history")
llm=OpenAI(temperature=0)
agent_chain = initialize_agent(tools, llm, agent=AgentType.CONVERSATIONAL_REACT_DESCRIPTION, verbose=True, memory-memory)
agent_chain.run(input="how is the weather i wismar?")
Execution example;
> Entering new AgentExecutor chain...
Thought: Do I need to use a tool? Yes
Action: Current Search
Action Input: weather in Wismar
Observation: 66°F
Thought: Do I need to use a tool? No
AI: The current weather in Wismar is 66°F.
I've been trying to find a solution in the Langchain documentation, but found nothing.