コンテンツにスキップ

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.

pathRole
examples/python-agentic-chat/app/assistant.tsxassistant-ui runtime, Hosted Connect handoff, and state rendering
examples/python-agentic-chat/backend/app.pyFastAPI endpoints and OpenAI Agents streaming conversion
examples/python-agentic-chat/backend/state.pyAssistantTransport state helpers
packages/sdk-python/src/vel4ai/integrations/openai_agents.pyPer-model-call OpenAI Agents adapter

Install Python packages from the monorepo checkout:

Terminal window
python -m pip install -e packages/sdk-python[agents] -e examples/python-agentic-chat/backend

Start the backend:

Terminal window
python -m uvicorn backend.app:app --reload --port 8100 --app-dir examples/python-agentic-chat

Start the frontend:

Terminal window
pnpm --filter @vela/example-python-agentic-chat dev

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

The AssistantTransport state is a JSON object with:

fieldPurpose
messagesUser and assistant transcript
stepsTool calls and agent progress
activeAgentCurrent OpenAI Agents SDK agent name
readinessOptional readiness snapshot
errorUser-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.

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.

toolWhen it should be used
lookup_project_policyVela policy, audit, or Local LLM notes
inspect_delegation_readinessHosted Connect / delegation readiness before a model call
estimate_agent_run_costExpected model-call count, demo cost, and per-call authorization
compare_execution_sourcesVela Credits vs BYOK vs Local LLM tradeoffs
draft_revoke_test_planDelegation 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 した直後に何を確認すべきかテスト手順を書いて。
  1. Create or reuse a Hosted Connect delegation.
  2. Ask an agentic prompt that triggers the demo function tool.
  3. Confirm assistant-ui shows a tool step and final response.
  4. Confirm Vela audit shows authorization / execution entries for each OpenAI Agents model call.
  5. Revoke the delegation and confirm the next model call is denied before the provider call starts.