-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpydantic_ai_tool.py
More file actions
69 lines (53 loc) · 1.99 KB
/
pydantic_ai_tool.py
File metadata and controls
69 lines (53 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
"""
Ejentum Logic API -- Pydantic AI Tool
Type-safe tool definition for Pydantic AI agents. Uses Pydantic models
for input validation and structured output.
"""
import httpx
from pydantic_ai import Agent, RunContext, Tool
from pydantic import BaseModel
EJENTUM_URL = "https://ejentum-main-ab125c3.zuplo.app/logicv1/"
EJENTUM_KEY = "YOUR_EJENTUM_API_KEY"
class InjectionRequest(BaseModel):
query: str
mode: str = "reasoning"
async def get_injection(ctx: RunContext[None], query: str, mode: str = "reasoning") -> str:
"""Retrieve a cognitive injection from Ejentum's Logic API.
Call this before making complex judgments. The injection provides
suppression signals that block cognitive shortcuts.
Args:
query: Describe your current reasoning challenge in 1-2 sentences.
mode: "reasoning", "code", "anti-deception", "memory", or multi variants.
"""
async with httpx.AsyncClient(timeout=5) as client:
try:
r = await client.post(
EJENTUM_URL,
headers={
"Authorization": f"Bearer {EJENTUM_KEY}",
"Content-Type": "application/json",
},
json={"query": query, "mode": mode},
)
r.raise_for_status()
key = mode # response key matches mode name
return r.json()[0][key]
except Exception as e:
return f"Injection unavailable: {e}. Proceed with native reasoning."
agent = Agent(
"openai:gpt-4o",
system_prompt=(
"You are a senior analyst. Before making complex judgments, "
"call the get_injection tool to retrieve a cognitive injection. "
"Apply the injection's suppression signals before answering."
),
tools=[Tool(get_injection)],
)
async def main():
result = await agent.run(
"Why did our conversion rate drop 40% after the checkout redesign?"
)
print(result.data)
if __name__ == "__main__":
import asyncio
asyncio.run(main())