Building Your First Agent
Step-by-step guide to building a research agent.
Building Your First Agent
Build a research agent that takes a topic, calls tools, and returns a structured report. This is the SDK path: Agent + Task + AgentExecutor. For Near chat, start agx serve instead — see Quickstart.
Step 1: Set up
bash
1pip install agenticx2export OPENAI_API_KEY="your-key"
Step 2: Define tools
python
1from agenticx.tools import tool2import httpx34@tool5def search_web(query: str) -> str:6 """Search the web for information about a topic.78 Args:9 query: The search query10 """11 response = httpx.get(12 "https://api.search.com/search",13 params={"q": query, "key": "your-api-key"},14 timeout=30,15 )16 return response.text1718@tool19def fetch_page(url: str) -> str:20 """Fetch the first 5000 characters of a web page.2122 Args:23 url: The URL to fetch24 """25 response = httpx.get(url, follow_redirects=True, timeout=30)26 return response.text[:5000]
Replace the search URL with a real API. @tool wraps a function as a FunctionTool / BaseTool.
Step 3: Define the agent
python
1from agenticx import Agent23research_agent = Agent(4 id="research-agent",5 name="Research Assistant",6 role="Senior Research Analyst",7 goal=(8 "Conduct thorough research on any given topic. "9 "Find authoritative sources, synthesize information, "10 "and produce clear, well-structured reports."11 ),12 backstory=(13 "You are an expert researcher with a background in "14 "information synthesis and critical analysis."15 ),16 organization_id="my-research-org",17 max_iterations=15,18 tools=[search_web, fetch_page],19)
Step 4: Run a task
python
1from agenticx import Task, AgentExecutor2from agenticx.llms import OpenAIProvider34task = Task(5 description="Research: Multi-agent AI systems and software development",6 expected_output=(7 "A structured research report with:\n"8 "1. Executive summary\n"9 "2. Key findings\n"10 "3. Detailed analysis\n"11 "4. Sources and references"12 ),13)1415executor = AgentExecutor(16 llm_provider=OpenAIProvider(model="gpt-4o"),17 tools=[search_web, fetch_page],18)19result = executor.run(agent=research_agent, task=task)20print(result)
run returns a dict with the final output and metadata, not a bare string.
Next
- Agent runtime —
AgentRuntimevsAgentExecutor - Tools — MCP, Studio tools, OpenAPI
- Near Desktop — same stack, chat UI instead of a script