Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Streamlit Integration #275

Open
slavakurilyak opened this issue Feb 26, 2024 · 16 comments
Open

Streamlit Integration #275

slavakurilyak opened this issue Feb 26, 2024 · 16 comments

Comments

@slavakurilyak
Copy link

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

Related issue here

@slavakurilyak
Copy link
Author

Here's an example implementation by @amadad:

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

@speaks999
Copy link

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.

@slavakurilyak
Copy link
Author

slavakurilyak commented Feb 28, 2024

@tonykipkemboi do you want tackle this one?

Your trip_planner_agent would benefit from this

@speaks999
Copy link

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

@slavakurilyak
Copy link
Author

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)

@speaks999
Copy link

speaks999 commented Feb 29, 2024

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.

@slavakurilyak
Copy link
Author

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

@tonykipkemboi
Copy link

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.

@slavakurilyak
Copy link
Author

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

@chrispangg
Copy link
Contributor

chrispangg commented Mar 5, 2024

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],
      )
    

@speaks999
Copy link

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

@chrispangg
Copy link
Contributor

PR for the suggested change here

@tonykipkemboi
Copy link

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

@chrispangg
Copy link
Contributor

chrispangg commented Mar 11, 2024

PR merged - also added an example to the PR for printing steps in Streamlit
#333

@slavakurilyak
Copy link
Author

@chrispangg really appreciate you implementing this

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

@Pusse-01
Copy link

Pusse-01 commented May 5, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants