Step-by-step guide to building your first AI agent
In this guide, we’ll build a research assistant agent that can search the web, analyze information, and create reports. By the end, you’ll understand the core concepts of building agents with Slide.
import asynciofrom tyler import Agent, Thread, Message, EventTypefrom lye import WEB_TOOLS, FILES_TOOLSasync def main(): # Create your agent agent = Agent( name="research-assistant", model_name="gpt-4o", purpose="To help with research by finding, analyzing, and summarizing information", tools=[ *WEB_TOOLS, # Can search and fetch web content *FILES_TOOLS # Can read and write files ] ) # Create a conversation thread thread = Thread() thread.add_message(Message( role="user", content="Research the latest developments in renewable energy and create a summary" )) # Watch the agent work in real-time print("🔍 Researching renewable energy...\n") async for event in agent.stream(thread): # Show content as it's generated if event.type == EventType.LLM_STREAM_CHUNK: print(event.data['content_chunk'], end="", flush=True) # Show when tools are used elif event.type == EventType.TOOL_SELECTED: print(f"\n\n🔧 Using {event.data['tool_name']}...", flush=True) elif event.type == EventType.TOOL_RESULT: print(f"✓ Done\n", flush=True)if __name__ == "__main__": asyncio.run(main())
Choosing between .stream() and .run():
Use agent.stream(thread) for:
Chat interfaces and real-time UIs
Watching the agent work (great for debugging)
Progressive UI updates as content generates
Use await agent.run(thread) for:
Batch processing and automation
Testing (when you just need the final result)
Simple scripts where streaming isn’t needed
Most interactive applications will want .stream() - it’s what makes agents feel alive!
3
Run Your Agent
uv
python
Copy
uv run agent.py
When you run the agent, here’s what happens:
Thread Creation: A conversation thread is created to hold messages
Message Processing: The agent receives your message and plans its approach
Tool Usage: The agent uses web search tools to find information
Response Generation: The agent synthesizes findings into a response
# See available toolsfrom lye import WEB_TOOLS, FILES_TOOLS, IMAGE_TOOLSprint("🔧 Web Tools:")for tool in WEB_TOOLS: print(f" - {tool['definition']['name']}: {tool['definition']['description']}")print("\n📁 File Tools:")for tool in FILES_TOOLS: print(f" - {tool['definition']['name']}: {tool['definition']['description']}")
You can also give your agent specific tools:
Copy
from lye.web import search, fetchfrom lye.files import write_fileagent = Agent( name="focused-researcher", model_name="gpt-4", purpose="To search and save information", tools=[search, fetch, write_file] # Only these specific tools)
For comprehensive debugging and observability, Slide integrates with Weights & Biases Weave. Weave provides:
Visual traces of every agent action and decision
LLM call tracking with inputs, outputs, and token usage
Tool execution monitoring to see which tools were called and their results
Performance insights to identify bottlenecks
Error tracking with full context
Copy
import weave# Initialize Weave tracingweave.init("my-research-agent")# Now all agent operations will be traced automatically# View traces at https://wandb.ai/your-username/my-research-agent
Weave traces are invaluable for debugging complex agent behaviors. You can see exactly what prompts were sent to the LLM, what tools were called, and how the agent made its decisions.
The purpose parameter significantly affects agent behavior. Be specific:
Copy
# Goodpurpose="To research technology topics and create detailed, well-sourced reports"# Too vaguepurpose="To help with stuff"
Tool Selection
Only give your agent the tools it needs:
Copy
# For a research agenttools=[*WEB_TOOLS, *FILES_TOOLS]# For an image analysis agenttools=[*IMAGE_TOOLS, *FILES_TOOLS]# For a data processing agenttools=[*FILES_TOOLS]
Error Handling
Always handle potential errors:
Copy
try: result = await agent.run(thread)except Exception as e: print(f"❌ Error: {e}") # Handle gracefully
Processing Complex Files
Your agent can handle various file types out of the box. For enhanced capabilities:
Scanned PDFs: Install poppler for OCR support
This is optional - your agent will work fine without it for most use cases.