crewAI
crewAI copied to clipboard
Streamlit Integration
It would be great to see Streamlit integration with crewAI so these crews can escape from their terminals, pun intended
Related issue here
Here's an example implementation by @amadad:
https://github.com/amadad/civic-agentcy
The example above shows the final output but not the log messages. Need to be able to have the logs write to st.write_stream somehow.
Using step_callback=st.write in the agent startup will get you started but there must be a more elegant way.
Verbose
mode is also useful since response can be streamed in real-time and it does not require a function to be called after each step of the agent (aka Step CallBack
)
A complete Streamlit example, with streaming chat showing all agent responses, complete with agent icons, would probably increase usage of CrewAI by 10-30% or more. Can someone just create that? Thanks Modifying the trip planner agent would be a great example. Allowing people to interact with human-in-the-loop agents is also necessary.
Check out multi-agent-streamlit-ui by @camel-ai for inspiration
So I played with the trip planner app last night for a few minutes trying to implement the streaming logs on the app under st.status.
The challenge lies in redirecting the logger outputs from CrewAI agents into the Streamlit app in a way that allows for near real-time updates.
I tried redirecting the logs to the Streamlit UI but that did not work so I ended up modifying the Crewai source code under the utilities/logger.py and was able to get some logs printed on the app but some others (the green log text in console) haven't got to it yet. This is not the best way to do this and maybe I just need a little brainstorming session with @joaomdmoura to get this part working.
@joaomdmoura it would be great to have your input on this
I was able to get some of the green log text in the console printed by modifying the agent.py file with the following:
- Add a callback init variable to agent.py
callbacks: Optional[List[InstanceOf[BaseCallbackHandler]]] = Field( default=None, description="Callbacks to be executed" )
- In create_agent_executor() in the same Agent.py file, add the following callback to the CrewAgentExecutor
self.agent_executor = CrewAgentExecutor( agent=RunnableAgent(runnable=inner_agent), **executor_args, callbacks=self.callbacks, )
- In your own code, pass in the callback handler (using the StdOutCallbackHandler as an example) when creating the agent:
from langchain_core.callbacks import StdOutCallbackHandler callback_handler = StdOutCallbackHandler() finance_researcher = Agent( role="Finance Research Analyst", goal="Provide up-to-date finance market data analysis", backstory="An expert analyst with a keen eye for market trends.", tools=[web_search, web_scraper], callbacks=[callback_handler], )
This would be a great start. The next step would be to facilitate the human in the loop somehow. @joaomdmoura do you have a plan for this? Are you going to incorporate the change above? Thx
PR for the suggested change here
Thanks for getting this out @chrispangg. I barely got time to keep looking into this.
PR merged - also added an example to the PR for printing steps in Streamlit https://github.com/joaomdmoura/crewAI/pull/333
@chrispangg really appreciate you implementing this
@joaomdmoura It would be great to see a how-to guide for this streamlit integration
I want to take human inputs when executing the agents. According to the documentation we can take it from the terminal by enabling hunan_input from the task. But any methods to get it from the streamlit app and give it to the agent? Any method to get user feedbacks while executing the agents?
This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.