# quickstart_anthropic.py
import asyncio
import os
from anthropic import AsyncAnthropic
from clavenar_agent_sdk import ClavenarDenied, ClavenarOptions, ClavenarPending, clavenar_wrap
correlation_id = ""
async def on_verdict(verdict, ctx):
global correlation_id
correlation_id = getattr(verdict, "correlation_id", None) or correlation_id
print(f"[clavenar] {verdict.kind} {ctx.tool_name} {correlation_id}")
async def main():
global correlation_id
client = clavenar_wrap(
AsyncAnthropic(),
ClavenarOptions(
endpoint="http://localhost:8088",
token=os.environ.get("CLAVENAR_LITE_TOKEN") or None,
mode="observe",
on_verdict=on_verdict,
),
)
try:
await client.messages.create(
model=os.environ.get("ANTHROPIC_MODEL", "claude-opus-4-7"),
max_tokens=256,
tools=[{
"name": "lookup_account",
"description": "Look up account risk for a customer account.",
"input_schema": {
"type": "object",
"properties": {"account_id": {"type": "string"}},
"required": ["account_id"],
},
}],
tool_choice={"type": "tool", "name": "lookup_account"},
messages=[{"role": "user", "content": "Use lookup_account for acct_123 and summarize risk."}],
)
except ClavenarPending as e:
correlation_id = e.correlation_id
except ClavenarDenied as e:
correlation_id = e.correlation_id or correlation_id
print(f"CORRELATION_ID={correlation_id}")
asyncio.run(main())
# quickstart_openai.py
import asyncio
import os
from openai import AsyncOpenAI
from clavenar_agent_sdk import ClavenarDenied, ClavenarOptions, ClavenarPending, clavenar_wrap
correlation_id = ""
async def on_verdict(verdict, ctx):
global correlation_id
correlation_id = getattr(verdict, "correlation_id", None) or correlation_id
print(f"[clavenar] {verdict.kind} {ctx.tool_name} {correlation_id}")
async def main():
global correlation_id
client = clavenar_wrap(
AsyncOpenAI(),
ClavenarOptions(
endpoint="http://localhost:8088",
token=os.environ.get("CLAVENAR_LITE_TOKEN") or None,
mode="observe",
on_verdict=on_verdict,
),
)
try:
await client.chat.completions.create(
model=os.environ.get("OPENAI_MODEL", "gpt-4-turbo"),
messages=[{"role": "user", "content": "Use lookup_account for acct_123 and summarize risk."}],
tools=[{
"type": "function",
"function": {
"name": "lookup_account",
"description": "Look up account risk for a customer account.",
"parameters": {
"type": "object",
"properties": {"account_id": {"type": "string"}},
"required": ["account_id"],
},
},
}],
tool_choice={"type": "function", "function": {"name": "lookup_account"}},
)
except ClavenarPending as e:
correlation_id = e.correlation_id
except ClavenarDenied as e:
correlation_id = e.correlation_id or correlation_id
print(f"CORRELATION_ID={correlation_id}")
asyncio.run(main())