from agntor import Agntor, guard, redact
from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate
client = Agntor(api_key="agntor_live_xxx", agent_id="my-agent", chain="base")
llm = ChatOpenAI(model="gpt-4o")
chain = ChatPromptTemplate.from_messages([
("system", "You are a financial analysis agent."),
("human", "{input}"),
]) | llm
async def trusted_pipeline(user_input: str, target_agent: str):
# 1. Guard input
g = guard(user_input)
if g.classification == "block":
return {"error": "Input blocked", "violations": g.violation_types}
# 2. Check trust
score = await client.trust.score(target_agent)
if score.score < 60:
return {"error": f"Agent trust too low: {score.score}/100 ({score.tier})"}
# 3. Create escrow
escrow = await client.escrow.create(
agent_id=target_agent,
amount=10_000_000,
task_description=user_input,
)
# 4. Run chain
raw = chain.invoke({"input": user_input}).content
# 5. Redact output
safe = redact(raw)
# 6. Settle
task_id = escrow.get("task", {}).get("id") or escrow.get("taskId")
if task_id:
await client.settle.release(task_id)
return {
"output": safe.redacted,
"trust": {"score": score.score, "tier": score.tier},
"redacted_items": len(safe.findings),
"escrow_settled": True,
}