OneLi ב־Pydantic AI

איך נותנים לסוכן שבנוי ב־Pydantic AI לבצע שיחות טלפון בעברית דרך OneLi, לעקוב אחרי השיחה, לענות להתייעצויות ולקבל את התוצאה.

ב־Pydantic AI גרסה 2 משתמשים ב־MCPToolset, שמזהה את סוג התעבורה לבד, ומעבירים אותו ל־toolsets של הסוכן.

התקנה

  1. יוצרים מפתח API ב־oneli.io/app/connect ושומרים אותו במשתנה הסביבה ONELI_API_KEY בשרת.
  2. מתקינים את החבילות:
Terminal
pip install pydantic-ai   # or: pip install "pydantic-ai-slim[mcp,openai]"

נבדק מול: pydantic-ai 2.59.0

MCP וכלי REST

Python
import os, uuid, httpx
from pydantic_ai import Agent
from pydantic_ai.mcp import MCPToolset

oneli = MCPToolset("https://mcp.oneli.io/mcp",
                   headers={"Authorization": f"Bearer {os.environ['ONELI_API_KEY']}"})  # or auth=os.environ["ONELI_API_KEY"]
agent = Agent("openai:gpt-5", instructions="Use OneLi to place calls.", toolsets=[oneli])

@agent.tool_plain
async def create_call_task(to_number: str, goal: str, instructions: str | None = None) -> dict:
    """Have OneLi place a phone call. to_number in E.164."""
    body = {"idempotency_key": str(uuid.uuid4()), "to_number": to_number, "goal": goal}
    if instructions: body["instructions"] = instructions
    async with httpx.AsyncClient(timeout=30) as c:
        r = await c.post("https://api.oneli.io/v1/call-tasks", json=body,
                         headers={"Authorization": f"Bearer {os.environ['ONELI_API_KEY']}"})
        r.raise_for_status(); return r.json()

print(agent.run_sync("Call +972… and book a table for 2 at 19:00").output)

שימו לב

  • בגרסה 2 הוסרה המחלקה MCPServerStreamableHTTP והוחלפה ב־MCPToolset.
  • הפרמטר headers מאומת מקוד המקור של 2.59.0; הדוגמה היחידה בתיעוד משתמשת ב־auth.
  • בגרסה 1.x: ‏MCPServerStreamableHTTP(url, headers=…) עם toolsets=[…].

מספרי טלפון: OneLi מקבלת מספר ישראלי בכל פורמט נפוץ (050-1234567,‏ +972501234567). כשהשיחה מתחילה, הסוכן ממשיך עם get_call_events או עם GET /v1/call-tasks/:id/events כדי לעקוב, לענות להתייעצויות ולקבל את הסיכום.

מה הלאה

מקורות: pydantic.dev/docs/ai/mcp/client/ · pydantic.dev/docs/ai/overview/migration/