How to get the output of each agent, so i can show it to the streamlit, how i integrate with that

How to get the output of each agent, when i called kickoff method, so i can show in streamlit the reply of each agent.

I have been just dumping the final results of each task to a separate unique file and that has worked well.

Maybe you could just read those files back into Streamlit or whatever you are using and clean it up or parse out what you want to display.
From the user manual you can access the task output in various forms:

# Accessing the task output
task_output = task.output

print(f"Task Description: {task_output.description}")
print(f"Task Summary: {task_output.summary}")
print(f"Raw Output: {task_output.raw}")
if task_output.json_dict:
    print(f"JSON Output: {json.dumps(task_output.json_dict, indent=2)}")
if task_output.pydantic:
    print(f"Pydantic Output: {task_output.pydantic}")

There is also a thought of creating an Agent that just keeps track of what the other agents are doing and summarizes that in a single report. This would require some experimenting.

Hi joab, i understand this approach, meanwhile if the whole flow takes 1 minute to complete and dump in the file, at that time ui have to wait, i dont have to wait for that time, may be there is some other solution exist we have to wait for that, if some one else reply,

Agree there probably is a much easier method. For now, maybe you could pipe the verbose output that shows up in the command window in real-time to a file that you keep checking for updates (file size) and parse that info as it is available using a try/except file read in Streamlit to avoid I/O conflicts?

crewai run > verbose_output.txt

from streamlit check for file size change using something like watchdog, and then try/except a file copy statement to a temp file, then read that temp file into streamlit and parse it to show what you want sooner than waiting until the end.

HI @joab.io, My another query instead of using litellm interanl call if i have my own completion calls written how to utilize that, if i can utilize my completion call in the Agents, that will solve this issue?

Hey, guys. You can do something like that:

from crewai.agents.parser import AgentAction, AgentFinish
from crewai.agents.crew_agent_executor import ToolResult

def step_callback(step):
    if isinstance(step, AgentAction):
        logger.info(f"Action: {step.text}")
    elif isinstance(step, AgentFinish):
        logger.info(f"Finish: {step.text}")
    elif isinstance(step, ToolResult):
        logger.info(f"Tool Result: {step.result}")

crew = Crew(..., step_callback=step_callback)
1 Like

Thanks, i will try the solution

Hey i treid he solution, eventhough it is same in terminal, logging is not working.

working, is there any other development regarding this context

actually, i am searching for this solution for few days.
for my experience, i think the key point is to get the stream output from llm rather than the crewai. and the long time for waitting which is caused by waitting llm’s response.
To give you an example. if you use stream api request to llm, you can get response realtime. then you can get this stream output to the window.

after i searching for the doc from crewai and litellm(intergrated by crewai), i think the best way is to use litellm’s stream mode replace the default llm.

the version 0.108.0 supports the stream output
that’s fine

I am also facing similar issue i need to show the result of different agents based on a button click (conditionally) on streamlit. So tried to create seperate crew kickoff but facing issue doing this.

Well, I think a pretty solid approach would be to set up an event listener. That way, you can snag just the events you’re interested in and then process them.

You can get the full scoop from the official CrewAI documentation on Event Listeners. And hey, check out this other thread too – it’s got a good example of a producer/consumer pattern that might be just what you need.

1 Like

yes this is correct and updated way of doing it.

the correct (and updated) way is to use the event listeners as @Max_Moura mentioned. i created a tutorial a few months back on how to do this as well before we had the event listener implementation. you might still find it useful.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.