langchain icon indicating copy to clipboard operation
langchain copied to clipboard

How to know which tool(s) been used on `agent_chain.run`?

Open mzhadigerov opened this issue 2 years ago • 8 comments
trafficstars

Hi! After I create an agent using initialize_agent , I can call the agent using agent.run.

I can see the steps on the terminal e.g.:

Thought: Do I need to use a tool? Yes
Action: Index A,
Action Input: ....

but in the end, the run function returns only a final output (string). How can I get the intermediate steps as well? Especially, whether the agent used a tool or not?

mzhadigerov avatar Apr 04 '23 19:04 mzhadigerov

+1, I'm still trying to figure out a nice way to do this

dxv2k avatar Apr 05 '23 13:04 dxv2k

Hi @dxv2k ! Can you check out this thread? I was able to implement the functionality using the method proposed in the thread:

2068

mzhadigerov avatar Apr 05 '23 13:04 mzhadigerov

Wow, really nice approach. Do you have any output that I can see? Thanks a lot.

Hi @dxv2k ! Can you check out this thread? I was able to implement the functionality using the method proposed in the thread:

2068

dxv2k avatar Apr 05 '23 13:04 dxv2k

@dxv2k Sorry man, I'm out of my pc now, but can send an example output later.

mzhadigerov avatar Apr 05 '23 13:04 mzhadigerov

Thanks man, I'll try to implement it tomorrow. I have a side question, does it also store the input of each tool used?

dxv2k avatar Apr 05 '23 13:04 dxv2k

@dxv2k you mean context from documents? I don't think so. At least, I could not find it

mzhadigerov avatar Apr 05 '23 13:04 mzhadigerov

Context alone is not enough, I want to extract metadata and query too therefore I need to get every tool it had used with the input of each tool. It would be really helpful if we could figure out a way to do it. My current implementation is that I add another property to track it, not really nice tbh.

dxv2k avatar Apr 05 '23 14:04 dxv2k

I was trying to have the same functionality as well. Why dont you try to get the raw response from agent (its a dict) and parse its intermediate steps to know the tool as well as tool_input.

KeshavSingh29 avatar Jun 02 '23 02:06 KeshavSingh29

+1

tajpouria avatar Jun 04 '23 22:06 tajpouria

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

From what I understand, the issue was about determining which tool(s) were used during the agent_chain.run process in LangChain. @dxv2k proposed a method and you implemented it. There was a discussion about accessing the intermediate steps and whether the input of each tool used is stored. @KeshavSingh29 suggested getting the raw response from the agent and parsing its intermediate steps to know the tool and tool_input.

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 and understanding. Let us know if you have any further questions or concerns!

dosubot[bot] avatar Sep 21 '23 16:09 dosubot[bot]