# Define a simple function toolasync def get_weather(city: str) -> str: """Get the weather for a given city.""" return f"The weather in {city} is 73 degrees and Sunny."# Create the agentagent = AssistantAgent( name="weather_agent", model_client=model_client, tools=[get_weather], system_message="You are a helpful assistant.", reflect_on_tool_use=True, model_client_stream=True,)
4
Build Streamlit interface
Create a Streamlit app to run the agent and render responses:
main.py
async def main() -> None: st.title("Autogen Generative UI Chat") task = st.text_input("Enter a task:", value="What is the weather in New York?") if st.button("Run"): with st.spinner("Running..."): result = await agent.run(task=task) if result.messages: final_message = result.messages[-1] thesys.render_response(final_message.content) await model_client.close()if __name__ == "__main__": asyncio.run(main())
5
Run the application
export THESYS_API_KEY=<your-api-key>streamlit run main.py
Access your app at http://localhost:8501 to interact with your Autogen agent through Thesys-powered UI.
View the code
Find more examples and complete code on our GitHub repository.