from tyler import Agent# Minimal agent configurationagent = Agent( name="assistant", model_name="gpt-4", purpose="To be a helpful assistant")# With additional configurationagent = Agent( name="gpt4-assistant", model_name="gpt-4", purpose="To assist with various tasks", temperature=0.7)
from tyler import Agentfrom lye import WEB_TOOLS, FILES_TOOLS, IMAGE_TOOLSfrom lye.web import search, fetchfrom lye.files import read_file, write_filefrom lye.image import analyze_image# Using tool groupsagent = Agent( name="research-assistant", model_name="gpt-4", purpose="To help with research tasks", tools=[ *WEB_TOOLS, # All web tools *FILES_TOOLS, # All file tools analyze_image # Specific image tool ])# Or using specific toolsagent = Agent( name="focused-assistant", model_name="gpt-4", purpose="To search and save information", tools=[search, fetch, read_file, write_file])
Agents can intelligently select and use tools based on the task:
from tyler import Agent, Thread, Message# Create thread and messagethread = Thread()message = Message( role="user", content="Search for recent AI developments and save a summary")thread.add_message(message)# Agent automatically chooses the right toolsresult = await agent.run(thread)# Agent will: 1) Use web.search, 2) Use web.fetch for details, 3) Use files.write
thread = Thread()message = Message( role="user", content=""" 1. Find the top 3 Python web frameworks 2. Compare their features 3. Create a comparison chart 4. Save the analysis """)thread.add_message(message)result = await agent.run(thread)
With proper thread management, agents maintain conversation context:
from tyler import Agent, Thread, Message, ThreadStore# Set up persistent storagethread_store = await ThreadStore.create("sqlite+aiosqlite:///conversations.db")agent = Agent( name="assistant", model_name="gpt-4", thread_store=thread_store)# Create a threadthread = Thread(id="research-session")# First querymessage1 = Message(role="user", content="What is FastAPI?")thread.add_message(message1)result = await agent.run(thread)# Save the threadawait thread_store.save_thread(result.thread)# Follow-up uses contextmessage2 = Message(role="user", content="How does it compare to Flask?")result.thread.add_message(message2)final_result = await agent.run(result.thread)# Agent knows we're talking about FastAPI
from lye import FILES_TOOLSagent = Agent( name="safe-agent", model_name="gpt-4", purpose="To safely read and analyze files", tools=[FILES_TOOLS[0]], # Just read_file tool tool_choice="auto", # or "none", "required", or specific tool name parallel_tool_calls=True # Enable parallel execution)
from lye import IMAGE_TOOLSfrom lye.files import read_csv, write_file# Image specialistimage_agent = Agent( name="image-expert", model_name="gpt-4", purpose="You are an expert at image analysis and manipulation", tools=IMAGE_TOOLS)# Data specialistdata_agent = Agent( name="data-analyst", model_name="gpt-4", purpose="You are a data analysis expert", tools=[read_csv, write_file] # Add your data analysis tools)
# Note: validation_fn is not a current Tyler feature# Instead, use the evaluation framework for validationfrom tyler.eval import AgentEval, Conversation, Expectationeval = AgentEval( name="validation_test", conversations=[ Conversation( user="Analyze this data", expect=Expectation( custom=lambda response: len(response["content"]) > 100 ) ) ])
Use clear, descriptive names that indicate the agent’s purpose:
# Goodagent = Agent( name="customer-support-agent", model_name="gpt-4", purpose="To help customers with product questions")# Not as clearagent = Agent(name="agent1", model_name="gpt-4")
2. Limit tool access
Only provide tools the agent actually needs:
from lye.slack import send_message, read_channelfrom lye.notion import search_pages# Good - specific tools for the taskemail_agent = Agent( name="email-assistant", model_name="gpt-4", purpose="To manage email communications", tools=[send_message, read_channel, search_pages])# Avoid - too many unnecessary toolsfrom lye import TOOLS # All available toolsemail_agent = Agent( name="email-assistant", model_name="gpt-4", tools=TOOLS # Includes unrelated tools)
3. Use appropriate models
Match model capabilities to task complexity:
# Simple taskssimple_agent = Agent( name="formatter", model_name="gpt-3.5-turbo", purpose="To format text")# Complex reasoningcomplex_agent = Agent( name="analyzer", model_name="gpt-4", purpose="To perform deep analysis")
4. Handle errors gracefully
Always implement error handling:
from tyler.exceptions import AgentError, ToolErrortry: thread = Thread() message = Message(role="user", content=task) thread.add_message(message) result = await agent.run(thread)except ToolError as e: print(f"Tool failed: {e}") # Retry with different approachexcept AgentError as e: print(f"Agent error: {e}") # Log and handle appropriately
Tyler provides a comprehensive evaluation framework for testing your agents:
from tyler.eval import AgentEval, Conversation, Expectation, ToolUsageScorer# Define test scenarioseval = AgentEval( name="agent_test", conversations=[ Conversation( user="Calculate the sum of 15 and 27", expect=Expectation( mentions=["42"], completes_task=True ) ) ], scorers=[ToolUsageScorer()])# Run tests with mock toolsresults = await eval.run(agent)
Key testing features:
Mock Tools: Prevent real API calls during testing
Flexible Expectations: Test content, behavior, and tool usage
Multiple Scorers: Evaluate tone, task completion, and more
Multi-turn Conversations: Test complex interaction flows
Always test your agents with the evaluation framework before deployment. See the full evaluation guide for details.