0

I am trying to build a bot using gpt-3.5-turbo and the langchain tools. I am trying to create an own Tool/Agent for that. The point of the Bot will be, that it can answer questions asked about specific topics, where information can only be found on Confluence (Atlassian Web-based Wiki). The bot is already recognizing, that my custom tool should be used and it's also handling the Action Input. However, it doesn't call the tool (which is functioning by itself). The code (excluding keys and private data) is as following:

import os
os.environ['OPENAI_API_KEY'] = PRIVATE

from langchain.chat_models import ChatOpenAI
from langchain.chains.conversation.memory import ConversationBufferMemory
from langchain.tools import StructuredTool
from langchain.agents import initialize_agent, AgentType, load_tools
from langchain.document_loaders import ConfluenceLoader
from langchain.indexes import VectorstoreIndexCreator

# importing llm
turbo_llm = ChatOpenAI(
    temperature = 0,
    model_name = 'gpt-3.5-turbo'
)

loader = ConfluenceLoader(url=PRIVATE, token=PRIVATE)
documents = loader.load(
    space_key=PRIVATE_SPACE_KEY, page_ids=PRIVATE_IDS, include_attachments=False, limit=1, max_pages=1, keep_markdown_format=True
index = VectorstoreIndexCreator().from_documents(documents)

# Confluence Search Tool
def confluence_search(searchParam: str="") -> str:
    """Get information about COMPANY NAME specifics using Confluence. Can help if the bot can't handle the information or the information can't be found online. The searchParam is the Action input."""
    return index.query(searchParam)

confluence_search_tool = StructuredTool.from_function(confluence_search)

# Adding the Confluence Search tool to the llm
# tools =  [confluence_search_tool]
tools = load_tools([], llm=turbo_llm)
tools = tools + [confluence_search_tool]

# conversational agent memory
memory = ConversationBufferMemory(
    memory_key = 'chat_history',
    k = 5, # remembers 3 messages
    return_messages = True
)

PREFIX = '''You are a bot helping with specific questions from COMPANY workers. They often ask about things, where the only place you can find information is the Confluence. Thus, you must often use Confluence to look up stuff. If you can't find anything about the asked topic, tell the User you don't know an answer.'''

FORMAT_INSTRUCTIONS = """To use a tool, please use the following format:
'''
Thought: Do I need to use a tool? Yes
Action: the action to take, should be one of [{tool_names}]
Action Input: the input to the action
Observation: the result of the action
'''

"""

SUFFIX = '''
Begin!

Instructions: {input}
{agent_scratchpad}
'''

# creation of agent
conversational_agent = initialize_agent(
    agent = AgentType.STRUCTURED_CHAT_ZERO_SHOT_REACT_DESCRIPTION, # only works with STRUCTURED_CHAT_ZERO_SHOT_REACT_DESCRIPTION, however it doesn't remember previous messages
    tools = tools,
    llm = turbo_llm,
    verbose = True,
    return_intermediate_steps = True,
    agent_kwargs = {
        'prefix': PREFIX,
        'format_instructions': FORMAT_INSTRUCTIONS,
        'suffix': SUFFIX
        }
    #memory = memory
)


conversational_agent("What is the Countrynum of Germany?") # Testquestion not working

The output is as follows:

[1m> Entering new AgentExecutor chain...[0m
[32;1m[1;3mThought: Do I need to use a tool? Yes
Action: confluence_search
Action Input: QUESTION RELATED (private)
[0m

[1m> Finished chain.[0m

As you can see, it tells its thought, action and action_input. However it doesn't tell me any observation.

desertnaut
  • 57,590
  • 26
  • 140
  • 166
Tiiill
  • 47
  • 1
  • 3
  • From your format_instruction, try removing "Observation: the result of the action". Let AI decide it for you, no need to explicitly specify observation. – ZKS Aug 10 '23 at 19:12

0 Answers0