Skip to main content

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:

  1. A list of AgentConfig objects, each specifying:

  2. Basic agent metadata, such as avatar and initial greeting

  3. A Pydantic.AI agent, with or without tools (including MCP)

  4. A deps object to use with the agent, as described by Pydantic.AI. The deps may also be used to store agent state

  5. A sidebar function for agent-specific sidebar rendering

  6. An AppConfig, specifying:

  7. Global page metadata, such as tab title and icon

  8. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

opaiui-0.8.0.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

opaiui-0.8.0-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

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

Hashes for opaiui-0.8.0.tar.gz
Algorithm Hash digest
SHA256 67d499ef1469cc0e36b22846fb0bfd4fdb5972b372e92eb7beff6812ed2bbfb9
MD5 d4f441595968e820b8b1beb71be1b798
BLAKE2b-256 d9b5c7fa237c8a56260aa43b44c7fac40350a0ee5232b81e4f7d57b3f3f35ce6

See more details on using hashes here.

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

Hashes for opaiui-0.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c3fc43a64316a248b36d8f4dd9d23ab761ef54e1d832419a76fd9d9a442c375a
MD5 fb586260f94018b0f429e62a507e6979
BLAKE2b-256 9da845d2318c6e11fbbdb2098da3db5be6dda479ef6c959b2e3207bc38ea1902

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page