ମୁଖ୍ୟ ବିଷୟବସ୍ତୁକୁ ଛାଡ଼ନ୍ତୁ
PYDANTIC AI ଇଣ୍ଟେଗ୍ରେସନ୍

Pydantic AI ଦେୟ ଇଣ୍ଟେଗ୍ରେସନ୍।

Pydantic AI package ନାହିଁ, ଏବଂ ଆପଣଙ୍କୁ ତାହା ଦରକାର ମଧ୍ୟ ନାହିଁ। @agent.tool_plain ସହିତ ଏକ typed function register କରନ୍ତୁ, ଆସଲ blockchain0x client କୁ call କରନ୍ତୁ, ଏବଂ ଆପଣଙ୍କ agent Base ଉପରେ USDC move କରିପାରିବ।

ସଂକ୍ଷିପ୍ତ ଉତ୍ତର

Pydantic AI-ନିର୍ଦ୍ଦିଷ୍ଟ କୌଣସି package ନାହିଁ, ଏବଂ ଆପଣଙ୍କୁ ଦରକାର ମଧ୍ୟ ନାହିଁ। Pydantic AI ସହିତ function କୁ validated tool ରେ ପରିଣତ କରେ, ସେଥିପାଇଁ ଆପଣ ସତ୍ୟ Python client କୁ typed function ଭିତରେ wrap କରନ୍ତୁ ଏବଂ agent USDC ପଠାଇପାରିବ, invoice settle କରିପାରିବ, ଏବଂ wallet ପଢ଼ିପାରିବ। ଏହା OpenAI, Anthropic, Google, Mistral, Groq, ଏବଂ ଅନ୍ୟ ସମସ୍ତ Pydantic AI provider ସହିତ କାମ କରେ, କାରଣ tool model କୁ ନୁହେଁ, HTTP API କୁ call କରେ। Payments Base ରେ settle ହୁଏ।

କାହିଁକି ଟାଇପ୍ କରାଯାଇଥିବା ପେମେଣ୍ଟ ଟୁଲ୍‌ସ୍

Pydantic AI ର ଟାଇପିଂ ଜିତେ। ଦେୟ ପାଇଁ ଏହାକୁ ବ୍ୟବହାର କରନ୍ତୁ।

Pydantic AI ର ମୂଳ ଉଦ୍ଦେଶ୍ୟ ହେଉଛି strong typing: agent inputs typed, outputs typed, dependencies typed, retries typed। Framework ଖରାପ data କୁ boundary ରେ ନିଜେ reject କରେ, LLM call ମାଧ୍ୟମରେ ଏହାକୁ ପ୍ରସାରିତ ହେବାକୁ ଦିଏନାହିଁ। ଆପଣଙ୍କ wallet tool ଏହା ଉପରେ ସିଧା ଚାଲେ - arguments କୁ types ସହ declare କରନ୍ତୁ, ଏବଂ Pydantic AI model କୁ call କରିବା ପୂର୍ବରୁ signature ଏବଂ docstring ରୁ validated schema ତିଆରି କରେ।

ପ୍ରାୟୋଗିକ ଲାଭ: ଯଦି model base-unit string ପରିବର୍ତ୍ତେ float ସହିତ send_usdc call କରିବାକୁ ଚେଷ୍ଟା କରେ, ଆମ ପାଖକୁ କୌଣସି HTTP call ହେବା ପୂର୍ବରୁ failure Pydantic ର validation layer ରେ ହୁଏ। API ରୁ cryptic field path ସହିତ 422 ମିଳିବା ପରିବର୍ତ୍ତେ ଆପଣ ଉପଯୁକ୍ତ message ସହିତ ସ୍ପଷ୍ଟ ValidationError ଦେଖନ୍ତି। generic adapter ଧରିବା ପରିବର୍ତ୍ତେ ଏଠାରେ client କୁ ନିଜେ wrap କରିବାର ସମ୍ପୂର୍ଣ୍ଣ କାରଣ ଏହାହିଁ - wire ପର୍ଯ୍ୟନ୍ତ typing ଆପଣ ରଖିଥାନ୍ତି।

ଇନ୍ସ୍ଟଲେସନ୍

Pydantic AI ଏବଂ core SDK ଇନଷ୍ଟଲ୍ କରନ୍ତୁ। ଦୁଇଟି key।

ଯୋଡିବା ପାଇଁ blockchain0x Pydantic AI package ନାହିଁ। ଆପଣ Pydantic AI (Python 3.10+) ଏବଂ ଆସଲ blockchain0x core SDK install କରନ୍ତୁ, ତାପରେ ତଳେ ଥିବା function ଲେଖନ୍ତୁ। ସମ୍ପୂର୍ଣ୍ଣ dependency list ଏତିକି ହିଁ।

ଇନ୍ସ୍ଟଲ୍
pip install pydantic-ai blockchain0x
ପରିବେଶ ଚଳକଗୁଡିକ
export OPENAI_API_KEY=sk-...
export BLOCKCHAIN0X_API_KEY=sk_test_...   # sk_test_ = Base Sepolia, sk_live_ = Base mainnet

OPENAI_API_KEY (କିମ୍ବା ଆପଣ ବ୍ୟବହାର କରୁଥିବା କୌଣସି provider ପାଇଁ ସମାନ key)। BLOCKCHAIN0X_API_KEY ହେଉଛି ଆପଣଙ୍କ dashboard ରୁ sk_test_ testnet କିମ୍ବା sk_live_ mainnet key; client ଏହାକୁ environment ରୁ ପଢ଼େ। ଯଦି ଆପଣଙ୍କ agent ଟଙ୍କା ମଧ୍ୟ ଗ୍ରହଣ କରେ, webhook handler କୁ ଅତିରିକ୍ତ ଭାବେ BLOCKCHAIN0X_WEBHOOK_SECRET ଦରକାର।

ରେସିପି

ଏକ ଟାଇପ୍ କରାଯାଇଥିବା ଫଙ୍କ୍ସନ୍ ଯାହା ଦେୟ କରେ, ଏକ ଟୁଲ୍ ଭାବରେ ପଞ୍ଜିକୃତ।

ନିମ୍ନରେ ସମ୍ପୂର୍ଣ୍ଣ integration ଅଛି। send_usdc real blockchain0x client କୁ call କରେ; @agent.tool_plain type hints ଏବଂ docstring ରୁ ତିଆରି schema ସହିତ ଏହାକୁ register କରେ। ଏହାକୁ run କରନ୍ତୁ ଏବଂ agent Base ରେ USDC move କରେ, call ପୂର୍ବରୁ arguments validate ହୁଏ।

AGENT.PY
from pydantic_ai import Agent
from blockchain0x import Client

blockchain0x = Client()  # reads BLOCKCHAIN0X_API_KEY from the environment

agent = Agent(
    "openai:gpt-4o",
    system_prompt="You pay vendor invoices in USDC within owner-set limits.",
)

# Register a plain function as a tool. No dedicated package needed.
@agent.tool_plain
def send_usdc(agent_id: str, to: str, amount_wei: str) -> str:
    """Send a USDC payment from an agent wallet.

    amount_wei is USDC base units (6 decimals), so "10000" is 0.01 USDC.
    """
    return str(
        blockchain0x.payments.create(body={"agentId": agent_id, "to": to, "amountWei": amount_wei})
    )

result = agent.run_sync(
    "Pay 0.01 USDC from agent agt_123 to 0xVendor for the dataset."
)
print(result.output)

When the agent decides to pay, it calls send_usdc, the SDK submits the transfer, and you get a transaction hash back. amount_wei is base units, so 0.01 USDC is "10000". A sk_test_ key keeps it on Base Sepolia until you switch to sk_live_. Want a typed result object instead of a string? Set the agent's output_type to your own Pydantic model and return it from the tool. Add read and settle functions the same way.

ୱେବ୍‌ହୁକ୍ ହ୍ୟାଣ୍ଡଲିଂ

ସାଇନ୍ କରାଯାଇଥିବା ଓବ୍‌ହେକ୍ ସହିତ ଆସନ୍ତା ଦେୟଗୁଡିକୁ ନିଶ୍ଚୟ କରନ୍ତୁ।

ଯଦି ଆପଣଙ୍କ agent ମଧ୍ୟ USDC receive କରେ, polling ଚାଇଁତି ନୁହେଁ, webhook ଦ୍ୱାରା ଏହାକୁ confirm କରନ୍ତୁ। verify helper Node SDK ସହିତ ଆସେ; Python service ରେ ଆପଣ documented HMAC ଅନୁସାରେ ହାତେ verify କରନ୍ତି। ଯଦି ଆପଣ typed events ଚାହାନ୍ତି, ନିଜର Pydantic model define କରନ୍ତୁ ଏବଂ signature ସଠିକ୍ ହେବା ପରେ raw body କୁ model_validate_json କରନ୍ତୁ - typing ଆପଣଙ୍କ ଯୋଗ କରିବାକୁ ପଡ଼ିବ। ତଳେ FastAPI example ଅଛି।

ୱେବ୍‌ହୁକ୍.ପାଇ
import hmac, hashlib, os, time
from fastapi import FastAPI, Request, HTTPException

app = FastAPI()
SECRET = os.environ["BLOCKCHAIN0X_WEBHOOK_SECRET"].encode()

@app.post("/webhooks/payment")
async def receive(request: Request):
    raw = await request.body()  # RAW bytes - do not parse first
    sig = request.headers.get("X-Blockchain0x-Signature", "")
    ts = request.headers.get("X-Blockchain0x-Timestamp", "")
    parts = dict(p.split("=", 1) for p in sig.split(",") if "=" in p)
    t, v1 = parts.get("t", ts), parts.get("v1", sig)
    want = hmac.new(SECRET, t.encode() + b"." + raw, hashlib.sha256).hexdigest()
    if not hmac.compare_digest(want, v1) or abs(time.time() - int(t)) > 300:
        raise HTTPException(status_code=401)
    if request.headers.get("X-Blockchain0x-Event-Type") == "payment.received":
        await trigger_followup()  # USDC landed - run the next step
    return {"ok": True}

algorithm ଟି t.rawBody string ଉପରେ HMAC-SHA256, constant-time compare, ଏବଂ 300-second replay window ବ୍ୟବହାର କରେ। await request.body() ମାଧ୍ୟମରେ raw body ପଢ଼ନ୍ତୁ, କେବେ ମଧ୍ୟ request.json() re-serialized କରନ୍ତୁ ନାହିଁ, କାରଣ ଏହା signature ଆବର୍ତ୍ତିତ bytes କୁ ପରିବର୍ତ୍ତନ କରେ। shipped events ହେଉଛି payment.received, payment.sent, wallet.deployed, ଏବଂ webhook.test; branch କରିବା ପାଇଁ X-Blockchain0x-Event-Type header ଉପରେ narrow କରନ୍ତୁ।

ସୋର୍ସ ଏବଂ ଡକ୍ସ

ଆପଣ wrap କରୁଥିବା client open ଅଟେ। ଏହାକୁ ପଢ଼ନ୍ତୁ।

Clone କରିବା ପାଇଁ Pydantic AI starter package ନାହିଁ - ଉପରେ ଥିବା recipe ହିଁ integration। blockchain0x SDKs GitHub ଉପରେ open source ଅଟେ; ଏହି recipe Python SDK (blockchain0x-python) କୁ wrap କରେ, ଏବଂ docs ରେ full method surface ଅଛି। function bodies ପାଇଁ reference ଭାବେ ଏହାକୁ ପଢନ୍ତୁ।

github.com/tosh-labs/blockchain0x-python

Full SDK method surface ଏବଂ scopes the docs ରେ documented ଅଛି। Base Sepolia ବିରୁଦ୍ଧରେ sk_test_ key ରୁ ଆରମ୍ଭ କରନ୍ତୁ, ପରେ function ଆପଣ ଆଶା କରୁଥିବାଭଳି କାମ କଲେ sk_live_ କୁ switch କରନ୍ତୁ।

ସାଧାରଣ ବିପଦ

ପାଇଡାଣ୍ଟିକ୍ AI-ନିର୍ଦ୍ଦିଷ୍ଟ ଜାଲକୁ ଏଡାଇବାକୁ ପାଞ୍ଚ ଜାଲ।

Pydantic AI ର ଶକ୍ତିଶାଳୀ ଟାଇପିଂ ଅଧିକାଂଶ ଇଣ୍ଟେଗ୍ରେସନ୍ ବଗ୍‌ଗୁଡିକୁ ସୀମାରେ ଧରେ; ଏହା ଗୋଟିଏ କିଛି ଯାହା ଚାଲିଯାଏ।

PITFALL 1

Pydantic AI package ନାହିଁ - ଆପଣ ଏକ tool register କରନ୍ତି

Blockchain0x LangChain ଏବଂ CrewAI ପାଇଁ adapters ସହିତ MCP server ମଧ୍ୟ ship କରେ; Pydantic AI ପାଇଁ dedicated package ନାହିଁ। ଉପରେ ଥିବା recipe ହିଁ path: ଏକ ସାଧାରଣ typed function, ଯାହାକୁ @agent.tool_plain ସହିତ decorate କରାଯାଇଛି ଏବଂ real blockchain0x client କୁ call କରେ। Pydantic AI validated tool schema build କରିବା ପାଇଁ signature ଏବଂ docstring ପଢେ, ଯାହା Pydantic AI ପାଇଁ ଆପଣ ଖୋଜୁଥିବା typing advantage ହିଁ।

PITFALL 2

amount କୁ string ରୂପେ ରଖନ୍ତୁ; Pydantic କୁ line ଧରିରଖିବାକୁ ଦିଅନ୍ତୁ

payments.create takes amountWei: a string of USDC base units (6 decimals), so 0.01 USDC is "10000" and 5 USDC is "5000000". Type the tool argument as str and Pydantic AI rejects a float at the boundary with a clear ValidationError, before any HTTP call. That is the whole point of doing this in Pydantic AI - the malformed value never reaches the API.

PITFALL 3

send_payment ପ୍ରାରମ୍ଭରେ 503 ଫେରାଇପାରେ

payments.create default ଭାବରେ retry କରେ ନାହିଁ ଏବଂ chain adapter ଆପଣଙ୍କ network ପାଇଁ wired ହେଉପର୍ଯ୍ୟନ୍ତ 503 ଫେରାଇପାରେ। error କୁ ଆପଣଙ୍କ tool ଭିତରେ ଧରନ୍ତୁ ଏବଂ model କାର୍ଯ୍ୟ କରିପାରିବା ପାଇଁ ଏକ ସ୍ପଷ୍ଟ message ଫେରାନ୍ତୁ, agent loop କରିବାକୁ ଦିଅନ୍ତୁ ନାହିଁ। auto-minted idempotency key ଅର୍ଥ manual retry ଦୁଇଥର ଭୁଗତାନ କରିବ ନାହିଁ।

PITFALL 4

ପ୍ରଦାତା-ପ୍ରିଫିକ୍ସ ମଡେଲ୍ ସ୍ଟ୍ରିଙ୍ଗ୍ସ

Pydantic AI ପ୍ରଦାତା-ପ୍ରିଫିକ୍ସ ମଡେଲ୍ ସ୍ଟ୍ରିଙ୍ଗ୍ସ ବ୍ୟବହାର କରେ: 'openai:gpt-4o', 'anthropic:claude-3-5-sonnet-latest', 'google-gla:gemini-1.5-pro'। ପ୍ରିଫିକ୍ସକୁ ଅବହେଳା କରିବା 'ଅଜଣା ମଡେଲ୍' ତ୍ରୁଟି ଦେଇଥାଏ। ଆପଣଙ୍କର ଟୁଲ୍ ପ୍ରଦାତା-ନିର୍ବାହୀ କାରଣ ଏହା HTTP API କୁ କଲ୍ କରେ, ମଡେଲ୍ ନୁହେଁ - ପ୍ରିଫିକ୍ସକୁ ସ୍ୱାଧୀନତାରେ ବଦଳାନ୍ତୁ ଏବଂ ୱାଲେଟ୍ କାର୍ଯ୍ୟ ସେମାନେ ଅପରିବର୍ତ୍ତିତ।

PITFALL 5

tool_plain vs tool (RunContext)

ଏହାର ଫଙ୍କ୍ସନ୍ ଚାଲିବାରୁ କିଛି ଆବଶ୍ୟକତା ନଥିଲେ @agent.tool_plain ବ୍ୟବହାର କରନ୍ତୁ, ଯଥା ଉପରେ। ଯଦି ଆପଣ ଟୁଲ୍‌ରେ ଏଜେଣ୍ଟଙ୍କର ନିର୍ଭରତା ଚାହାଁନ୍ତି (ପ୍ରତି-ଅନୁରୋଧ କ୍ଲାଇଏଣ୍ଟ ଆଇଡି, ଏକ ଖର୍ଚ୍ଚ କ୍ୟାପ୍), @agent.tool ବ୍ୟବହାର କରନ୍ତୁ ଏବଂ ପ୍ରଥମ ଆର୍ଗୁମେଣ୍ଟକୁ ctx: RunContext[Deps] ଭାବରେ ଘୋଷଣା କରନ୍ତୁ ଯାହା ctx.deps କୁ ପଢ଼ିବାକୁ। ଦୁଇଟିକୁ ମିଶାଇବା - tool_plain ଉପରେ ctx ଆର୍ଗୁମେଣ୍ଟକୁ ଘୋଷଣା କରିବା - ରେଜିଷ୍ଟ୍ରେସନ୍‌ରେ TypeError ଉତ୍ପନ୍ନ କରେ।

ପ୍ରାୟତଃ ପ୍ରଶ୍ନ

ତିନି Pydantic AI-ନିର୍ଦ୍ଦିଷ୍ଟ ପ୍ରଶ୍ନ।

ଇନଷ୍ଟଲ୍ କରିବାକୁ dedicated Pydantic AI package ଅଛି କି?

ନା। Pydantic AI ପୂର୍ବରୁ @agent.tool_plain (କିମ୍ବା context-aware tools ପାଇଁ @agent.tool) ସହ ଏକ function କୁ validated tool ରେ ପରିଣତ କରେ, ସେହିପାଇଁ ସତ୍ୟ path ହେଉଛି ଉପରେ ଦେଖାଯାଇଥିବା ପରି real blockchain0x client କୁ ନିଜେ wrap କରନ୍ତୁ। ଏକମାତ୍ର shipped framework packages ହେଉଛି blockchain0x-langchain ଏବଂ blockchain0x-crewai (ଦୁହେଁ Python) ସହ @blockchain0x/mcp server। Pydantic AI, dedicated adapter ନଥିବା ଅନ୍ୟ frameworks ଭଳି, ଏହି କେତେକ line ର recipe ହେଉଛି।

ଏହା LLM ପ୍ରଦାତାମାନେ (OpenAI, Anthropic, Google) ମଧ୍ୟରେ କାମ କରେ କି?

ହଁ। tool provider-agnostic - ଏହା Blockchain0x HTTP API କୁ call କରେ, କୌଣସି LLM-specific surface କୁ ନୁହେଁ। ଯେପର୍ଯ୍ୟନ୍ତ Pydantic AI provider (OpenAI, Anthropic, Google GLA, Google VertexAI, Groq, Cohere, Mistral, Bedrock) କୁ support କରେ, ସେଇ function କାମ କରେ। କେବଳ Agent constructor ରେ model string ବଦଳାନ୍ତୁ: 'openai:gpt-4o' ପରିବର୍ତ୍ତେ 'anthropic:claude-3-5-sonnet-latest'.

ମୁଁ କିପରି ଟାଇପ୍ ଇନପୁଟ୍ ଯୋଗ କରିବି, କିମ୍ବା ପଢିବା ଏବଂ ସେଟଲ୍ କରିବା ସହିତ ସହିତ ପଠାଇବି?

ଅଧିକ କଠୋର inputs ପାଇଁ, tool argument ଭାବରେ ଏକ Pydantic model ନିଅନ୍ତୁ ଏବଂ Pydantic AI ଏହାକୁ ଆପଣଙ୍କ ପାଇଁ validate କରେ - constrained decimals, address patterns, ଆପଣଙ୍କ ଦରକାର ଯାହାକି ହେଉ। read ଏବଂ settle ପାଇଁ, ସେହିପରି ଭାବରେ ଆଉ functions register କରନ୍ତୁ: blockchain0x.transactions.get ଏକ transaction ପଢ଼େ, blockchain0x.agents.get ଏବଂ blockchain0x.agents.list wallets ପଢ଼େ, ଏବଂ blockchain0x.payment_requests.settle dashboard ରେ ଆପଣ ସୃଷ୍ଟି କରିଥିବା ଏକ invoice କୁ on-chain proof ସହିତ settle କରେ। inbound payments ତଳର payment.received webhook ମାଧ୍ୟମରେ confirm ହୁଏ।

ଆପଣଙ୍କର ଏଜେଣ୍ଟକୁ ଟାଇପ୍ ପେମେଣ୍ଟ ଯୋଡନ୍ତୁ।

ପ୍ରକୃତ client କୁ wrap କରୁଥିବା କିଛି typed ଲାଇନ୍, install କରିବାକୁ package ନାହିଁ। Free to start.