File size: 762 Bytes
10757ec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
from langchain import hub
from langchain.agents import AgentExecutor, create_react_agent

def run_agent_executor(agent_executor: AgentExecutor, input_data: dict):
        for chunk in agent_executor.stream(input_data):
            if "actions" in chunk:
                for action in chunk["actions"]:
                    print(f"Calling Tool: `{action.tool}` with input `{action.tool_input}`")
            # Observation
            elif "steps" in chunk:
                for step in chunk["steps"]:
                    print(f"Tool Result: `{step.observation}`")
            # Final result
            elif "output" in chunk:
                print(f'Final Output: {chunk["output"]}')
            else:
                raise ValueError()
            print("---")