Opinionated Pydantic.AI User Interface
Project description
opaiui: Opinionated Pydantic.AI User Interface
Opaiui (oh-pie-you-eye) provides a simple but flexible Streamlit user interface for Pydantic.AI agents. The following features are supported:
- Streaming responses
- Realtime tool-calling status display
- Agent selection
- Shareable sessions (Upstash key required)
- Customizable sidebar user interface
- In-chat rendering of streamlit components via agent tool call
- Toggleable full message context
Installation
Usage
An opaiui application consists of:
-
A list of
AgentConfigobjects, each specifying: -
Basic agent metadata, such as avatar and initial greeting
-
A Pydantic.AI agent, with or without tools (including MCP)
-
A
depsobject to use with the agent, as described by Pydantic.AI. Thedepsmay also be used to store agent state -
A sidebar function for agent-specific sidebar rendering
-
An
AppConfig, specifying: -
Global page metadata, such as tab title and icon
-
A set of Streamlit-based rendering functions, which an agent may execute to display widgets
Basic Application
We'll start with some imports and a basic agent, assuming we have a defined OPENAI_API_KEY in .env (or the key
stored in an environment variable or secret, if deploying in the cloud).
from pydantic_ai import Agent
from opaiui import AgentConfig, AppConfig, AgentState
from opaiui.app import call_render_func
import streamlit as st
import dotenv
# put OPENAI_API_KEY=<key> in .env
dotenv.load_dotenv()
basic_agent = Agent('openai:gpt-4o')
We can optionally define a function to render a sidebar component for the agent when active. This function must be async, and take a deps (which will be passed from the agent deps, see below).
async def agent_sidebar(deps):
st.markdown("", allow_unsafe_html = True)
If we like, we could define multiple agents, and a unique sidebar rendering function for each. To use them with the app,
we collect them into a dictionary of AgentConfigs. Keys are used for identifying the agent by name in the UI:
agent_configs = {
"Basic Agent": AgentConfig(
agent = basic_agent,
deps = None,
description = "A basic agent.",
)
}
Changelog
- 0.8.0: First public release
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file opaiui-0.8.0.tar.gz.
File metadata
- Download URL: opaiui-0.8.0.tar.gz
- Upload date:
- Size: 10.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
67d499ef1469cc0e36b22846fb0bfd4fdb5972b372e92eb7beff6812ed2bbfb9
|
|
| MD5 |
d4f441595968e820b8b1beb71be1b798
|
|
| BLAKE2b-256 |
d9b5c7fa237c8a56260aa43b44c7fac40350a0ee5232b81e4f7d57b3f3f35ce6
|
File details
Details for the file opaiui-0.8.0-py3-none-any.whl.
File metadata
- Download URL: opaiui-0.8.0-py3-none-any.whl
- Upload date:
- Size: 11.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c3fc43a64316a248b36d8f4dd9d23ab761ef54e1d832419a76fd9d9a442c375a
|
|
| MD5 |
fb586260f94018b0f429e62a507e6979
|
|
| BLAKE2b-256 |
9da845d2318c6e11fbbdb2098da3db5be6dda479ef6c959b2e3207bc38ea1902
|