print("─" * 72)
print(" 5 · Agentic RAG — AI Navigates Your Knowledge Graph")
print("─" * 72)
AGENT_TOOLS = [
{
"type": "function",
"function": {
"name": "iwe_find",
"description": "Search the knowledge graph for documents matching a query. Returns a list of document keys.",
"parameters": {
"type": "object",
"properties": {
"query": {"type": "string", "description": "Search query"},
"roots_only": {"type": "boolean", "description": "Only return root/MOC documents", "default": False},
},
"required": ["query"],
},
},
},
{
"type": "function",
"function": {
"name": "iwe_retrieve",
"description": "Retrieve a document's content with linked context. Use depth>0 to follow outgoing links, context>0 to include parent documents.",
"parameters": {
"type": "object",
"properties": {
"key": {"type": "string", "description": "Document key to retrieve"},
"depth": {"type": "integer", "description": "How many levels of child links to follow (0-2)", "default": 1},
"context": {"type": "integer", "description": "How many levels of parent context (0-1)", "default": 0},
},
"required": ["key"],
},
},
},
{
"type": "function",
"function": {
"name": "iwe_tree",
"description": "Show the document hierarchy starting from a given key.",
"parameters": {
"type": "object",
"properties": {
"key": {"type": "string", "description": "Root document key"},
},
"required": ["key"],
},
},
},
{
"type": "function",
"function": {
"name": "iwe_stats",
"description": "Get statistics about the entire knowledge base.",
"parameters": {"type": "object", "properties": {}},
},
},
]
def execute_tool(name: str, args: dict) -> str:
If Name == "iwe_find":
Results = kg.find (args)["query"], roots_only=args.get("roots_only", False))
return json.dumps({"results": results})
"elif" name="=" "iwe_retrieve":
Content = kg.retrieve (
The args["key"],
depth=args.get("depth", 1),
context=args.get("context", 0),
)
Return content[:3000]
"elif" name="" "iwe_tree":
Return kg.tree["key"])
"elif" name="=" "iwe_stats":
Return to the Homepage json.dumps(kg.stats(), indent=2)
return "Unknown tool"
def run_agent(question: str, max_turns: int = 6, model: str = "gpt-4o-mini") -> str:
system_prompt = textwrap.dedent("""
Your AI assistant has access to your personal knowledge graph.
Navigate the graph using the available tools.
Workflow:
1. Find relevant documents using iwe_find
2. Use iwe_retrieve for reading content (set the depth=1 option to follow links).
3. To build a comprehensive understanding, follow relationships.
4. Combine information in multiple documents
Cite the documents that you used to find information.
Do not hesitate to say that you are unable to find sufficient information.
""")
The message = [
{"role": "system", "content": system_prompt},
{"role": "user", "content": question},
]
For turn within range (max_turns).
response = client.chat.completions.create(
model=model, messages=messages, tools=AGENT_TOOLS,
tool_choice="auto",
)
Response.choices = msg[0].message
If the msg.tool_calls are:
messages.append(msg)
For tc calls in msg.tool_calls
fn_name = tc.function.name
fn_args = json.loads(tc.function.arguments)
print(f" 🔧 Agent calls: {fn_name}({fn_args})")
result = execute_tool(fn_name, fn_args)
messages.append({
"role": "tool",
"tool_call_id": tc.id,
"content": result,
})
else:
Content returned msg
Return to the Homepage "Agent reached maximum turns without completing."
Question [
"How does our authentication system work, and what database tables does it depend on?",
"What is our deployment pipeline, and what are the performance SLO targets?",
"Give me a high-level overview of the entire project architecture.",
]
Questions, 1:
print(f"n{'═' * 72}")
print(f" Question {i}: {q}")
print(f"{'═' * 72}n")
Answer = run_agent (q)
print(f"n💡 Agent Answer:n{answer}n")
print("n✅ Section 5 complete — Agentic RAG demonstrated.n")
Trending
- OpenAI Releases GPT-5.5, a Absolutely Retrained Agentic Mannequin That Scores 82.7% on Terminal-Bench 2.0 and 84.9% on GDPval
- Your Favorite AI Gay Thirst Traps: The Men Behind them
- Mend Releases AI Safety Governance Framework: Masking Asset Stock, Danger Tiering, AI Provide Chain Safety, and Maturity Mannequin
- Google DeepMind Introduces Decoupled DiLoCo: An Asynchronous Coaching Structure Attaining 88% Goodput Below Excessive {Hardware} Failure Charges
- Mend.io releases AI Security Governance Framework covering asset inventory, risk tiering, AI Supply Chain Security and Maturity model
- Stanford Students Wait in Line to Hear From Silicon Valley Royalty at ‘AI Coachella’
- Google Cloud AI Research introduces ReasoningBank: a memory framework that distills reasoning strategies from agent successes and failures.
- Equinox Detailed implementation with JAX Native Moduls, Filtered Transformations, Stateful Ladders and Workflows from End to end.

