crewAI icon indicating copy to clipboard operation
crewAI copied to clipboard

Streamlit Integration

Open slavakurilyak opened this issue 11 months ago • 16 comments

It would be great to see Streamlit integration with crewAI so these crews can escape from their terminals, pun intended

Related issue here

slavakurilyak avatar Feb 26 '24 18:02 slavakurilyak

Here's an example implementation by @amadad:

https://github.com/amadad/civic-agentcy

slavakurilyak avatar Feb 27 '24 15:02 slavakurilyak

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.

speaks999 avatar Feb 28 '24 18:02 speaks999

@tonykipkemboi do you want tackle this one?

Your trip_planner_agent would benefit from this

slavakurilyak avatar Feb 28 '24 23:02 slavakurilyak

Using step_callback=st.write in the agent startup will get you started but there must be a more elegant way.

speaks999 avatar Feb 29 '24 00:02 speaks999

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)

slavakurilyak avatar Feb 29 '24 18:02 slavakurilyak

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.

speaks999 avatar Feb 29 '24 19:02 speaks999

Check out multi-agent-streamlit-ui by @camel-ai for inspiration

slavakurilyak avatar Mar 01 '24 11:03 slavakurilyak

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.

tonykipkemboi avatar Mar 01 '24 13:03 tonykipkemboi

@joaomdmoura it would be great to have your input on this

slavakurilyak avatar Mar 01 '24 14:03 slavakurilyak

I was able to get some of the green log text in the console printed by modifying the agent.py file with the following:

  1. Add a callback init variable to agent.py
        callbacks: Optional[List[InstanceOf[BaseCallbackHandler]]] = Field(
            default=None, description="Callbacks to be executed"
        )
    
  2. 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,
       )
    
  3. 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],
      )
    

chrispangg avatar Mar 05 '24 22:03 chrispangg

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

speaks999 avatar Mar 05 '24 23:03 speaks999

PR for the suggested change here

chrispangg avatar Mar 09 '24 21:03 chrispangg

Thanks for getting this out @chrispangg. I barely got time to keep looking into this.

tonykipkemboi avatar Mar 10 '24 09:03 tonykipkemboi

PR merged - also added an example to the PR for printing steps in Streamlit https://github.com/joaomdmoura/crewAI/pull/333

chrispangg avatar Mar 11 '24 23:03 chrispangg

@chrispangg really appreciate you implementing this

@joaomdmoura It would be great to see a how-to guide for this streamlit integration

slavakurilyak avatar Mar 16 '24 02:03 slavakurilyak

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?

Pusse-01 avatar May 05 '24 10:05 Pusse-01

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.

github-actions[bot] avatar Aug 20 '24 10:08 github-actions[bot]