langchain icon indicating copy to clipboard operation
langchain copied to clipboard

Agent Executor Chain

Open fynn3003 opened this issue 1 year ago • 1 comments

I want to host a python agent on Gradio. It all works good. Im struggling when wanting to display not only the answer but also the AgentExecutor chain. How can I edit the code, so that also the AgentExecutor chain will be printed in the Gradio app. The Code snippet for that part is the following:

def answer_question(question):
    agent_executor = create_python_agent(
        llm=OpenAI(temperature=0, max_tokens=1000),
        tool=PythonREPLTool(),
        verbose=True
    )
    answer = agent_executor.run(question)
    return answer

ifaces = gr.Interface(
    fn=answer_question,
    inputs=gr.inputs.Textbox(label="Question"),
    outputs=gr.outputs.Textbox(label="Answer"),
    title="Question Answering Agent",
    description="A simple question answering agent."
)

fynn3003 avatar Apr 25 '23 08:04 fynn3003

You can use the callback manager to tap into the agent execution life cycle and update your UI accordingly.

Here is something I did: https://github.com/lifan0127/ai-research-assistant/blob/6695c3aad830554a31c3170dfe15b6fd2ff26988/src/modules/views/chat.ts#L77

lifan0127 avatar Apr 26 '23 03:04 lifan0127

I share a similar inquiry, wherein I aim to showcase the utilization of the AgentExecutor within the gradio output. I'm seeking "Python-based" solutions for this matter. While I have reviewed the previous response, it pertains to the TypeScript version. Your assistance is greatly appreciated.

1chooo avatar Aug 10 '23 07:08 1chooo

Hi, @fynn3003! I'm Dosu, and I'm helping the LangChain team manage their backlog. I wanted to let you know that we are marking this issue as stale.

Based on my understanding, you opened this issue requesting guidance on how to modify the code to display the AgentExecutor chain in addition to the answer in a Gradio app. lifan0127 suggested using the callback manager to tap into the agent execution life cycle and provided an example. This solution can be used to modify the code and achieve the desired functionality. Additionally, 1chooo also expressed a similar inquiry and requested Python-based solutions.

Before we close this issue, we wanted to check with you if it is still relevant to the latest version of the LangChain repository. If it is, please let us know by commenting on the issue. Otherwise, feel free to close the issue yourself or it will be automatically closed in 7 days.

Thank you for your contribution to the LangChain repository!

dosubot[bot] avatar Nov 09 '23 16:11 dosubot[bot]