Open-source AI coworkers that each get a computer of their own: a browser, files and tools, with every action decided before it happens and recorded after. Bring any AG-UI agent.
Start the Pydantic AI Bot on an Ollama model named with its tag (#610)
kevin4d1a514d906c
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex 965ba5f7..2f233476 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -304,6 +304,13 @@ jobs:. .venv-agno/bin/activatepython -m pip install --requirement agent-agno/requirements.txt --requirement agent-agno/requirements-test.txtpython -m pytest agent-agno/tests -q+ - name: Pydantic AI model-choice regression+ run: |+ set -euo pipefail+ python -m venv .venv-pydantic-ai+ . .venv-pydantic-ai/bin/activate+ python -m pip install --requirement agent-pydantic-ai/requirements.txt --requirement agent-pydantic-ai/requirements-test.txt+ python -m pytest agent-pydantic-ai/tests -q- run: bun install --frozen-lockfile- run: bun test tests/compose.test.ts- run: docker compose --env-file /dev/null --profile harness config --format json >/dev/nulldiff --git a/CHANGELOG.md b/CHANGELOG.mdindex 33e090c8..498d8881 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -16,6 +16,14 @@ Compose passes when the setup screen names none, so the run ended in `Unsupporteparameter the model does not take is now dropped instead, the way the LlamaIndex Bot already doesit. The Anthropic key and an OpenAI-compatible endpoint behave as before.+### The Pydantic AI Bot starts on an Ollama model named with its tag++Ollama names every model with a tag after a colon, as in `llama3.1:8b`, and that is the name the+setup screen passes on for an OpenAI-compatible endpoint. The Pydantic AI Bot took any colon in the+model's name to mean the name already carried a provider, so Pydantic AI read `llama3.1` as one,+refused it as unknown, and the Bot never started. A model's name now carries a provider only when it+begins with the chosen provider's own, as in `anthropic:claude-sonnet-4-5`.+## 0.0.13### Fresh desktop setup installs its runtime before sign-indiff --git a/agent-pydantic-ai/requirements-test.txt b/agent-pydantic-ai/requirements-test.txtnew file mode 100644index 00000000..a91d60c6--- /dev/null+++ b/agent-pydantic-ai/requirements-test.txt@@ -0,0 +1,2 @@+httpx==0.28.1+pytest==9.0.2diff --git a/agent-pydantic-ai/src/main.py b/agent-pydantic-ai/src/main.pyindex c65f83b1..28ebe4b2 100644--- a/agent-pydantic-ai/src/main.py+++ b/agent-pydantic-ai/src/main.py@@ -15,10 +15,15 @@ TOKEN_HEADER = "x-openbot-agent-token"def _model_id() -> str:- """`provider:model`, which is the form Pydantic AI names a model in."""+ """`provider:model`, which is the form Pydantic AI names a model in.++ A colon in `BOT_MODEL` names the provider only when it follows the provider's own name. Any+ other colon is part of the model's name: Ollama tags every model with one, as in `llama3.1:8b`,+ and Pydantic AI read the part before it as a provider, refused an unknown one and started no Bot.+ """provider = (os.environ.get("BOT_PROVIDER") or "openai").strip()model = (os.environ.get("BOT_MODEL") or "gpt-4o-mini").strip()- return model if ":" in model else f"{provider}:{model}"+ return model if model.startswith(f"{provider}:") else f"{provider}:{model}"agent = Agent(_model_id())diff --git a/agent-pydantic-ai/tests/test_main.py b/agent-pydantic-ai/tests/test_main.pynew file mode 100644index 00000000..d9de661a--- /dev/null+++ b/agent-pydantic-ai/tests/test_main.py@@ -0,0 +1,203 @@+import importlib+import json+import socket+import sys+import threading+import time+from pathlib import Path++import pytest+import uvicorn+from fastapi import FastAPI, Request+from fastapi.responses import StreamingResponse+from fastapi.testclient import TestClient++sys.path.insert(0, str(Path(__file__).resolve().parents[1]))++TOKEN = "test-token"+RUN = {+ "threadId": "thread-1",+ "runId": "run-1",+ "state": {},+ "messages": [{"id": "m1", "role": "user", "content": "Say hello"}],+ "tools": [],+ "context": [],+ "forwardedProps": {},+}+++def _sse(events):+ async def stream():+ for name, data in events:+ yield f"event: {name}\ndata: {json.dumps(data)}\n\n"++ return StreamingResponse(stream(), media_type="text/event-stream")+++def _provider_app(seen):+ app = FastAPI()++ # `openai:` is the Responses API in Pydantic AI, so that is the route an OpenAI key and an+ # OpenAI-compatible endpoint both reach.+ @app.post("/v1/responses")+ async def openai_responses(request: Request):+ body = await request.json()+ seen.append(("openai", body["model"]))+ response = {+ "id": "resp",+ "object": "response",+ "created_at": 0,+ "model": body["model"],+ "status": "in_progress",+ "output": [],+ "parallel_tool_calls": True,+ "tool_choice": "auto",+ "tools": [],+ }+ item = {"id": "msg", "type": "message", "role": "assistant", "status": "completed"}+ text = {"type": "output_text", "text": "hello", "annotations": []}+ done = {+ **response,+ "status": "completed",+ "output": [{**item, "content": [text]}],+ "usage": {+ "input_tokens": 1,+ "input_tokens_details": {"cached_tokens": 0},+ "output_tokens": 1,+ "output_tokens_details": {"reasoning_tokens": 0},+ "total_tokens": 2,+ },+ }+ return _sse(+ [+ ("response.created", {"type": "response.created", "sequence_number": 0, "response": response}),+ ("response.output_item.added", {"type": "response.output_item.added", "sequence_number": 1, "output_index": 0, "item": {**item, "status": "in_progress", "content": []}}),+ ("response.output_text.delta", {"type": "response.output_text.delta", "sequence_number": 2, "item_id": "msg", "output_index": 0, "content_index": 0, "delta": "hello", "logprobs": []}),+ ("response.output_item.done", {"type": "response.output_item.done", "sequence_number": 3, "output_index": 0, "item": {**item, "content": [text]}}),+ ("response.completed", {"type": "response.completed", "sequence_number": 4, "response": done}),+ ]+ )++ @app.post("/v1/messages")+ async def anthropic_messages(request: Request):+ body = await request.json()+ seen.append(("anthropic", body["model"]))+ message = {+ "id": "msg",+ "type": "message",+ "role": "assistant",+ "model": body["model"],+ "stop_sequence": None,+ }+ return _sse(+ [+ ("message_start", {"type": "message_start", "message": {**message, "content": [], "stop_reason": None, "usage": {"input_tokens": 1, "output_tokens": 0}}}),+ ("content_block_start", {"type": "content_block_start", "index": 0, "content_block": {"type": "text", "text": ""}}),+ ("content_block_delta", {"type": "content_block_delta", "index": 0, "delta": {"type": "text_delta", "text": "hello"}}),+ ("content_block_stop", {"type": "content_block_stop", "index": 0}),+ ("message_delta", {"type": "message_delta", "delta": {"stop_reason": "end_turn", "stop_sequence": None}, "usage": {"output_tokens": 1}}),+ ("message_stop", {"type": "message_stop"}),+ ]+ )++ return app+++def provider():+ seen = []+ with socket.socket() as probe:+ probe.bind(("127.0.0.1", 0))+ port = probe.getsockname()[1]+ server = uvicorn.Server(+ uvicorn.Config(_provider_app(seen), host="127.0.0.1", port=port, log_level="error")+ )+ thread = threading.Thread(target=server.run, daemon=True)+ thread.start()+ deadline = time.monotonic() + 10+ while not server.started and time.monotonic() < deadline:+ time.sleep(0.01)+ yield f"http://127.0.0.1:{port}", seen+ server.should_exit = True+ thread.join(timeout=10)+++def _endpoint(model):+ """What the desktop writes for an OpenAI-compatible endpoint serving `model`."""+ return (+ lambda base: {+ "BOT_PROVIDER": "",+ "BOT_MODEL": model,+ "OPENAI_API_KEY": "no-key-needed",+ "OPENAI_BASE_URL": f"{base}/v1",+ "ANTHROPIC_API_KEY": "",+ },+ ("openai", model),+ )+++CHOICES = {+ "an Anthropic key": (+ lambda base: {+ "BOT_PROVIDER": "anthropic",+ "BOT_MODEL": "claude-sonnet-4-5",+ "ANTHROPIC_API_KEY": "test-key",+ "ANTHROPIC_BASE_URL": base,+ "OPENAI_API_KEY": "",+ "OPENAI_BASE_URL": "",+ },+ ("anthropic", "claude-sonnet-4-5"),+ ),+ # Written the way Pydantic AI names a model, which still reaches that provider.+ "a model already named with its provider": (+ lambda base: {+ "BOT_PROVIDER": "anthropic",+ "BOT_MODEL": "anthropic:claude-sonnet-4-5",+ "ANTHROPIC_API_KEY": "test-key",+ "ANTHROPIC_BASE_URL": base,+ "OPENAI_API_KEY": "",+ "OPENAI_BASE_URL": "",+ },+ ("anthropic", "claude-sonnet-4-5"),+ ),+ "an OpenAI-compatible endpoint": _endpoint("local-model"),+ # Ollama names every model with its tag after a colon, which is the separator Pydantic AI puts+ # between a provider and a model.+ "an Ollama model named with its tag": _endpoint("llama3.1:8b"),+ # And a tag on a model that shares its name with a provider Pydantic AI knows.+ "an Ollama model named like a provider": _endpoint("mistral:7b"),+ "an OpenAI key": (+ lambda base: {+ "BOT_PROVIDER": "",+ "BOT_MODEL": "gpt-5.5",+ "OPENAI_API_KEY": "test-key",+ "OPENAI_BASE_URL": f"{base}/v1",+ "ANTHROPIC_API_KEY": "",+ },+ ("openai", "gpt-5.5"),+ ),+}++[email protected]("choice", list(CHOICES))+def test_a_run_reaches_the_model_the_setup_screen_chose(monkeypatch, provider, choice):+ base, seen = provider+ environment, expected = CHOICES[choice]+ monkeypatch.delenv("OPENAI_API_BASE", raising=False)+ monkeypatch.setenv("MANAGED_AGENT_TOKEN", TOKEN)+ monkeypatch.setenv("PYDANTIC_AI_NO_BANNER", "1")+ for key, value in environment(base).items():+ monkeypatch.setenv(key, value)++ from src import main++ main = importlib.reload(main)+ response = TestClient(main.app).post(+ "/", json=RUN, headers={"x-openbot-agent-token": TOKEN}+ )++ assert response.status_code == 200+ assert '"RUN_FINISHED"' in response.text+ assert '"RUN_ERROR"' not in response.text+ assert "hello" in response.text+ assert seen == [expected]