Mini-project: Cross-language agent service
Design the shared JSON contract between Python and TypeScript/Rust
A polyglot system succeeds when both sides enforce the exact same typed contract. Here, Python serves a verified research summary and validates the payload shape before returning it to a TypeScript frontend or Rust CLI.
Example
from pydantic import BaseModel
from praisonai import Agent
class CrossLangReply(BaseModel):
service: str
summary: str
confidence: float
py_specialist = Agent(
name='PythonRAGService',
instructions='Return service="python-rag", a 1-sentence summary, and confidence between 0 and 1.',
)
payload = py_specialist.chat('Enterprise SLA guarantees 99.95% uptime. Summarize it.', output_pydantic=CrossLangReply)
print('Contract verified:', payload.model_dump_json())Example explained
- CrossLangReply — Shared schema guaranteed by Pydantic in Python and typed interfaces/structs in TS/Rust.
- model_dump_json() — Produces deterministic JSON ready for HTTP/A2A transport.
Consume the service from TypeScript
Your TypeScript app calls the Python AgentOS endpoint with typed parsing — zero Python runtime required in your frontend container.
Example
interface CrossLangReply {
service: string;
summary: string;
confidence: number;
}
const res = await fetch('http://127.0.0.1:8000/agents/PythonRAGService/run', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ query: 'What is the enterprise SLA?' }),
});
const data: CrossLangReply = await res.json();
console.log(`[${data.service}] ${data.summary} (${data.confidence})`);Example explained
- interface CrossLangReply — Mirrors the Python Pydantic contract on the TypeScript side for end-to-end type safety.
Reference: documentation