# AI chat and agent apps over your data

Source: https://streamlit.io/generative-ai

Generative AI

## AI chat and agent apps *over your data*

Build assistants and agents right into your data apps, with chat, streaming responses, and step-by-step progress as an agent calls its tools. Connect them to any model or agent framework, or to Cortex on Snowflake, in the same Python as the rest of the app.

[Build a chat app](https://docs.streamlit.io/develop/tutorials/chat-and-llm-apps) [How agents use your apps](https://streamlit.io/agents#tools)

agent-app-demo.streamlit.app [Open app ↗](https://agent-app-demo.streamlit.app/)

The agent app demo plays back scripted analyses of synthetic data, so it runs without a model or an API key. It may take a moment to wake up. [View the source ↗](https://github.com/streamlit/demos/tree/main/agent-app)

Plain Python

## A whole assistant in one Python file

Chat, streaming responses, and the agent's progress are native Streamlit commands, so the assistant lives next to your data and your logic. Swap in any model or agent framework.

- [`st.chat_message`](https://docs.streamlit.io/develop/api-reference/chat/st.chat_message)
- [`st.status(type="compact")`](https://docs.streamlit.io/develop/api-reference/status/st.status)
- [`st.write_stream`](https://docs.streamlit.io/develop/api-reference/write-magic/st.write_stream)

[See the demo's source](https://github.com/streamlit/demos/tree/main/agent-app)

assistant.py

```
import streamlit as st
from agent import run_agent  # any model or agent framework

st.title("Ask the sales data")

if "messages" not in st.session_state:
    st.session_state.messages = []

for msg in st.session_state.messages:
    st.chat_message(msg["role"]).write(msg["content"])

if prompt := st.chat_input("Ask about revenue or churn"):
    st.session_state.messages.append({"role": "user", "content": prompt})
    st.chat_message("user").write(prompt)

    with st.chat_message("assistant"):
        with st.status("Agent steps", type="compact"):
            result = run_agent(prompt, on_step=st.write)
        reply = st.write_stream(result.stream())

    st.session_state.messages.append({"role": "assistant", "content": reply})
```

Built in

## Everything an AI app needs, in the same Python

Chat, streaming, and progress are native Streamlit commands, so an assistant sits right next to the tables and charts it talks about.

- ### Chat

  Chat interfaces with message history, avatars, and file attachments, and an input that can stop a long run.

  - [`st.chat_input`](https://docs.streamlit.io/develop/api-reference/chat/st.chat_input)
  - [`st.chat_message`](https://docs.streamlit.io/develop/api-reference/chat/st.chat_message)
- ### Streaming responses

  Show a model's answer as it arrives, from any generator, including OpenAI and LangChain streams.

  - [`st.write_stream`](https://docs.streamlit.io/develop/api-reference/write-magic/st.write_stream)
- ### Step-by-step progress

  Show each tool call as a step in a timeline while the agent works, and tuck its reasoning into a compact toggle.

  - [`st.status(type="step")`](https://docs.streamlit.io/develop/api-reference/status/st.status)
  - [`st.expander(type="compact")`](https://docs.streamlit.io/develop/api-reference/layout/st.expander)
- ### Feedback on every answer

  Collect thumbs or star ratings on each response, to evaluate and improve the assistant.

  - [`st.feedback`](https://docs.streamlit.io/develop/api-reference/widgets/st.feedback)
- ### Any model or framework

  Call any model or agent framework with a Python client, such as OpenAI, Anthropic, LangChain, or LlamaIndex.
- ### Cortex on Snowflake

  Call Cortex AI's models and functions from an app running inside Snowflake, under Snowflake's access controls.

  - [`st.connection("snowflake")`](https://docs.streamlit.io/develop/api-reference/connections/st.connection)

Agents and people

## The agent proposes. People decide.

An agent can draft the work, such as replenishment orders or forecast adjustments. People review, adjust, and approve it in a workflow app, checked by the same Python logic that produced the numbers.

- [`st.data_editor`](https://docs.streamlit.io/develop/api-reference/data/st.data_editor)
- [`st.login`](https://docs.streamlit.io/develop/api-reference/user/st.login)

[See workflow apps](https://streamlit.io/use-cases#workflows)

workflow-app-demo.streamlit.app [Open app ↗](https://workflow-app-demo.streamlit.app/)

An agent proposes replenishment orders. People review, adjust, and approve them in an editable table.

Agent-native

## An assistant in your app, and your app as a tool

- ### An assistant in your app

  People ask questions right next to the data, the charts, and the filters, and the assistant works through your own queries and Python logic.

  [Build a chat app →](https://docs.streamlit.io/develop/tutorials/chat-and-llm-apps)
- ### Your app as a tool for agents

  Every Streamlit app is also a tool that Claude, ChatGPT, Cursor, or any MCP client can use, with the same logic and access rules as people in the browser.

  [How agents use your apps →](https://streamlit.io/agents#tools)

## Frequently asked questions

- ### How do I build a chat app with Streamlit?

  Use [`st.chat_input`](https://docs.streamlit.io/develop/api-reference/chat/st.chat_input) for the input and [`st.chat_message`](https://docs.streamlit.io/develop/api-reference/chat/st.chat_message) for each message, keep the conversation in [`st.session_state`](https://docs.streamlit.io/develop/api-reference/caching-and-state/st.session_state), and stream the model's reply with [`st.write_stream`](https://docs.streamlit.io/develop/api-reference/write-magic/st.write_stream). For an agent, show its tool calls with [`st.status`](https://docs.streamlit.io/develop/api-reference/status/st.status), as a timeline of steps (`type="step"`) or a minimal toggle (`type="compact"`). The [agent app demo](https://agent-app-demo.streamlit.app/) puts all of these together, and its [source](https://github.com/streamlit/demos/tree/main/agent-app) is a good starting point. The [chat app tutorials](https://docs.streamlit.io/develop/tutorials/chat-and-llm-apps) walk through it step by step.
- ### Which models and agent frameworks work with Streamlit?

  Any model or framework with a Python client: OpenAI, Anthropic, Google, open models through Hugging Face or a local server, and agent frameworks such as LangChain and LlamaIndex. On Snowflake, call Cortex AI's models and functions from your app.
- ### How do I show what an agent is doing?

  Give each tool call or query its own [`st.status`](https://docs.streamlit.io/develop/api-reference/status/st.status) with `type="step"`. Consecutive steps form a connected timeline, and each one turns from a spinner into a check mark when it finishes. For the model's reasoning, use [`st.expander`](https://docs.streamlit.io/develop/api-reference/layout/st.expander) with `type="compact"`: a minimal toggle that stays out of the way until someone opens it. The answer streams in below with [`st.write_stream`](https://docs.streamlit.io/develop/api-reference/write-magic/st.write_stream).
- ### How do I keep API keys out of my code?

  Store them in `.streamlit/secrets.toml` locally, or in your deployment's secrets settings, and read them with [`st.secrets`](https://docs.streamlit.io/develop/api-reference/connections/st.secrets). Secrets stay on the server and never reach the browser. [More on secrets management](https://docs.streamlit.io/develop/concepts/connections/secrets-management).
- ### Can AI agents use my Streamlit apps?

  Yes. Every Streamlit app is also a tool that agents can call over MCP or plain HTTP, with no code changes. They read its tables and charts as data, set its filters, and submit its forms, through the same logic and access rules as a person in the browser. [How agents use your apps](https://streamlit.io/agents#tools).

Get started

## Build your first AI app

Set up your coding agent with Streamlit's skills, and ask for the assistant you need. The skills cover chat interfaces, streaming, and Snowflake.

[Chat app tutorials](https://docs.streamlit.io/develop/tutorials/chat-and-llm-apps) [Set up your coding agent](https://streamlit.io/agents#skills)

Prefer to start from a working app? [Start from the agent app demo's source](https://github.com/streamlit/demos/tree/main/agent-app).

Terminal

```
$ pip install streamlit
$ streamlit skills

> /developing-with-streamlit Build a chat
> app over the orders table that answers
> questions about revenue and shows each
> query it runs.
```
