Agents Module

The Agents module provides a framework for building autonomous AI agents that can use tools, maintain conversation memory, perform retrieval- augmented generation (RAG), execute multi-step pipelines, and enforce safety guardrails.

Configuration

example.py
python
Copied!
1from vorte import Vorte
2
3app = Vorte(
4 auto_load=True,
5 config={
6 "agents": {
7 "default_model": "gpt-4o",
8 "max_iterations": 10,
9 "timeout": 120,
10 "memory": {
11 "backend": "database",
12 "max_history": 100,
13 },
14 "guardrails": {
15 "input_validation": True,
16 "output_validation": True,
17 "max_tokens": 4096,
18 "blocked_patterns": [],
19 },
20 },
21 },
22)

Creating an Agent

example.py
python
Copied!
1from vorte.agents import Agent, AgentConfig
2
3agent = Agent(
4 name="assistant",
5 instructions="You are a helpful customer support agent. Be concise and friendly.",
6 model="gpt-4o",
7 temperature=0.7,
8 max_tokens=2048,
9)
10
11response = await agent.run("How do I reset my password?")
12print(response.content)
13print(response.tool_calls)
14print(response.usage)

Tools

Give agents the ability to take actions by defining tools they can call during execution.

search_knowledge_base.py
python
Copied!
1from vorte.agents import Agent, tool
2
3@tool(name="search_knowledge_base", description="Search the knowledge base for articles")
4async def search_knowledge_base(query: str, limit: int = 5) -> list[dict]:
5 results = await db.search_articles(query, limit=limit)
6 return [{"title": r.title, "content": r.content} for r in results]
7
8@tool(name="create_ticket", description="Create a support ticket for the user")
9async def create_ticket(user_id: int, subject: str, priority: str = "normal") -> dict:
10 ticket = await db.create_ticket(user_id=user_id, subject=subject, priority=priority)
11 return {"ticket_id": ticket.id, "status": ticket.status}
12
13@tool(name="get_order_status", description="Get the status of an order")
14async def get_order_status(order_id: str) -> dict:
15 order = await db.get_order(order_id)
16 return {"order_id": order.id, "status": order.status, "tracking": order.tracking_url}
17
18agent = Agent(
19 name="support_agent",
20 instructions="You are a support agent. Use tools to help customers.",
21 tools=[search_knowledge_base, create_ticket, get_order_status],
22)
23
24response = await agent.run("Where is my order ORD-12345?")
25# Agent automatically calls get_order_status and formulates a response

Memory

Agents maintain conversation history across interactions. Configure the memory backend and history limit.

example.py
python
Copied!
1from vorte.agents import Agent, Memory
2
3memory = Memory(backend="database", max_history=50)
4
5agent = Agent(
6 name="assistant",
7 instructions="Remember user preferences across conversations.",
8 memory=memory,
9 user_id="user_123",
10)
11
12response1 = await agent.run("My name is Alice and I prefer dark mode.")
13response2 = await agent.run("What is my name and preferred theme?")
14# The agent remembers: "Your name is Alice and you prefer dark mode."
15
16memory_summary = await memory.get_summary("user_123")
17print(memory_summary)

RAG (Retrieval-Augmented Generation)

example.py
python
Copied!
1from vorte.agents import Agent, RAG
2
3rag = RAG(
4 embedding_model="text-embedding-3-small",
5 vector_store="pgvector",
6 chunk_size=512,
7 chunk_overlap=50,
8 top_k=5,
9)
10
11await rag.index_document("docs/getting-started.md")
12await rag.index_document("docs/api-reference.md")
13await rag.index_directory("docs/")
14
15agent = Agent(
16 name="docs_assistant",
17 instructions="Answer questions based on the indexed documentation.",
18 rag=rag,
19)
20
21response = await agent.run("How do I configure the cache module?")
22# Agent retrieves relevant chunks from indexed docs before answering

Pipelines

Chain multiple agents and processing steps into ordered pipelines. Each step receives the output of the previous step.

example.py
python
Copied!
1from vorte.agents import Agent, Pipeline, Step
2
3researcher = Agent(
4 name="researcher",
5 instructions="Research the given topic thoroughly. Provide key findings.",
6 model="gpt-4o",
7)
8
9writer = Agent(
10 name="writer",
11 instructions="Write a clear, engaging article based on the research provided.",
12 model="gpt-4o",
13)
14
15editor = Agent(
16 name="editor",
17 instructions="Review the article for accuracy, clarity, and tone. Suggest improvements.",
18 model="gpt-4o",
19)
20
21pipeline = Pipeline(steps=[
22 Step(agent=researcher, name="research"),
23 Step(agent=writer, name="write"),
24 Step(agent=editor, name="edit"),
25])
26
27result = await pipeline.run("Write an article about Rust in web development")
28print(result.final_output)
29print(f"Steps completed: {len(result.step_results)}")

Guardrails

Enforce safety constraints on agent inputs and outputs. Guardrails validate, transform, or reject content before it enters or leaves the agent.

no_pii.py
python
Copied!
1from vorte.agents import Agent, Guardrail, InputGuardrail, OutputGuardrail
2
3async def no_pii(input_text: str) -> str:
4 patterns = [r"\b\d{3}-\d{2}-\d{4}\b", r"\b\d{16}\b"]
5 for pattern in patterns:
6 if re.search(pattern, input_text):
7 raise ValueError("Input contains sensitive information")
8 return input_text
9
10async def max_length(output_text: str) -> str:
11 if len(output_text) > 2000:
12 return output_text[:2000] + "... [truncated]"
13 return output_text
14
15agent = Agent(
16 name="safe_assistant",
17 instructions="You are a helpful assistant.",
18 guardrails=Guardrail(
19 input=[InputGuardrail(name="no_pii", handler=no_pii)],
20 output=[OutputGuardrail(name="max_length", handler=max_length)],
21 ),
22)

Prompt Templates

example.py
python
Copied!
1from vorte.agents import PromptTemplate
2
3template = PromptTemplate(
4 name="summarize",
5 template="""
6Summarize the following {{ content_type }} in {{ length }} sentences.
7
8Focus on: {{ focus }}
9
10Content:
11{{ content }}
12""",
13 variables=["content_type", "length", "focus", "content"],
14)
15
16prompt = template.render(
17 content_type="research paper",
18 length=3,
19 focus="key findings and methodology",
20 content=paper_text,
21)
22
23agent = Agent(name="summarizer", instructions="You summarize content accurately.")
24response = await agent.run(prompt)
Stay in the loop

Get Vorte release notes, module guides, and developer deep-dives. No spam — unsubscribe anytime.