Building Your First Agent
Step-by-step guide to building a research agent.
Building Your First Agent
This guide walks through building a real-world research agent step by step.
What We're Building
A research agent that:
- Accepts a research topic
- Searches the web for information
- Synthesizes findings into a structured report
Step 1: Set Up
bash
1pip install agenticx2export OPENAI_API_KEY="your-key"
Step 2: Define Your Tools
python
1# tools.py2from agenticx.tools import tool3import httpx45@tool6def search_web(query: str) -> str:7 """Search the web for information about a topic.89 Args:10 query: The search query1112 Returns:13 Search results as text14 """15 # Replace with your preferred search API16 response = httpx.get(17 "https://api.search.com/search",18 params={"q": query, "key": "your-api-key"}19 )20 return response.text2122@tool23def fetch_page(url: str) -> str:24 """Fetch the content of a web page.2526 Args:27 url: The URL to fetch2829 Returns:30 Page content as text31 """32 response = httpx.get(url, follow_redirects=True)33 return response.text[:5000] # First 5000 chars
Step 3: Define the Agent
python
1# agent.py2from agenticx import Agent34research_agent = Agent(5 id="research-agent",6 name="Research Assistant",7 role="Senior Research Analyst",8 goal=(9 "Conduct thorough research on any given topic. "10 "Find authoritative sources, synthesize information, "11 "and produce clear, well-structured reports."12 ),13 backstory=(14 "You are an expert researcher with a background in "15 "information synthesis and critical analysis."16 ),17 organization_id="my-research-org",18 max_iter=15,19 verbose=True20)
Step 4: Create and Run a Task
python
1# main.py2from agenticx import Task, AgentExecutor3from agenticx.llms import OpenAIProvider4from tools import search_web, fetch_page5from agent import research_agent67def research(topic: str) -> str:8 task = Task(9 id="research-task",10 description=f"Research: {topic}",11 expected_output=(12 "A structured research report with:\n"13 "1. Executive summary\n"14 "2. Key findings\n"15 "3. Detailed analysis\n"16 "4. Sources and references"17 )18 )1920 llm = OpenAIProvider(model="gpt-4o")21 executor = AgentExecutor(22 agent=research_agent,23 llm=llm,24 tools=[search_web, fetch_page]25 )2627 return executor.run(task)2829if __name__ == "__main__":30 result = research("Multi-agent AI systems impact on software development")31 print(result)
Step 5: Run It
bash
1python main.py
Enhancements
Add Memory
python
1from agenticx.memory import MemoryManager23memory = MemoryManager()4executor = AgentExecutor(agent=research_agent, llm=llm, tools=[...], memory=memory)
Add Observability
python
1from agenticx.observability import ConsoleTracer23tracer = ConsoleTracer()4executor = AgentExecutor(agent=research_agent, llm=llm, tools=[...], tracer=tracer)
Use the CLI
bash
1agx project create research-bot --template basic2cd research-bot3agx run agent.py --verbose