Python Agentic Chat
examples/python-agentic-chat demonstrates an assistant-ui frontend calling a FastAPI backend that runs OpenAI Agents SDK through the vel4ai Python SDK.
Files To Read
Section titled “Files To Read”| path | Role |
|---|---|
examples/python-agentic-chat/app/assistant.tsx | assistant-ui runtime, Hosted Connect handoff, and state rendering |
examples/python-agentic-chat/backend/app.py | FastAPI endpoints and OpenAI Agents streaming conversion |
examples/python-agentic-chat/backend/state.py | AssistantTransport state helpers |
packages/sdk-python/src/vel4ai/integrations/openai_agents.py | Per-model-call OpenAI Agents adapter |
Local Setup
Section titled “Local Setup”Install Python packages from the monorepo checkout:
python -m pip install -e packages/sdk-python[agents] -e examples/python-agentic-chat/backendStart the backend:
python -m uvicorn backend.app:app --reload --port 8100 --app-dir examples/python-agentic-chatStart the frontend:
pnpm --filter @vela/example-python-agentic-chat devThe frontend calls same-origin /api/agent/* routes by default. Next.js rewrites
those routes to the FastAPI backend at http://localhost:8100, which keeps
in-app browser preview ports on the same origin. Set AGENT_API_URL to change
the rewrite target, or NEXT_PUBLIC_AGENT_API_URL only when the browser should
call a backend origin directly.
Hosted Connect opens on https://app.vel4.ai by default. If a local or preview
Vela API returns a /connect?session=... URL on another origin, the backend
normalizes that URL to VELA_CONNECT_PUBLIC_BASE_URL.
Set VELA_AGENT_MODEL to a model that the connected Wallet source can execute.
If authorization returns capability_requirement_unmet, pick a model that is
both allowed by the delegation and available in the tenant model inventory.
State Shape
Section titled “State Shape”The AssistantTransport state is a JSON object with:
| field | Purpose |
|---|---|
messages | User and assistant transcript |
steps | Tool calls and agent progress |
activeAgent | Current OpenAI Agents SDK agent name |
readiness | Optional readiness snapshot |
error | User-visible error or non-allow reason |
OpenAI Agents stream events are mapped into assistant text deltas, tool step updates, active-agent changes, and error messages.
Demo Tools
Section titled “Demo Tools”The demo keeps tools local and deterministic. This lets the example show the agent loop, Vela authorization, and assistant-ui state updates without adding external API, database, or RAG setup.
| tool | When it should be used |
|---|---|
lookup_project_policy | Vela policy, audit, or Local LLM notes |
inspect_delegation_readiness | Hosted Connect / delegation readiness before a model call |
estimate_agent_run_cost | Expected model-call count, demo cost, and per-call authorization |
compare_execution_sources | Vela Credits vs BYOK vs Local LLM tradeoffs |
draft_revoke_test_plan | Delegation revoke and deny behavior checks |
Example prompts:
Vela の監査はどのステップで記録される?policy tool も使って。この delegation で agent を動かす前の readiness を確認して。OpenAI BYOK と Vela Credits と Local LLM の違いを比較して。この agent run の概算コストと model call ごとの authorization を説明して。delegation を revoke した直後に何を確認すべきかテスト手順を書いて。
Acceptance
Section titled “Acceptance”- Create or reuse a Hosted Connect delegation.
- Ask an agentic prompt that triggers the demo function tool.
- Confirm assistant-ui shows a tool step and final response.
- Confirm Vela audit shows authorization / execution entries for each OpenAI Agents model call.
- Revoke the delegation and confirm the next model call is denied before the provider call starts.