Quickstart Example

This guide will help you create your first agent and run basic tasks.

Installation

First, install AgenticFleet:

pip install agentic-fleet

Basic Agent

Create a simple conversational agent:

from agentic_fleet import Agent

# Create agent
agent = Agent(
    name="assistant",
    model="gpt-4"
)

# Chat with agent
async def main():
    response = await agent.chat(
        "What can you help me with?"
    )
    print(response)

# Run the example
import asyncio
asyncio.run(main())

Task Execution

Create an agent that can execute tasks:

from agentic_fleet import Agent
from agentic_fleet.tools import WebSearch, FileReader

async def execute_research():
    # Create agent with tools
    agent = Agent(
        name="researcher",
        model="gpt-4",
        tools=[WebSearch(), FileReader()]
    )
    
    # Define task
    task = """
    Research the latest developments in quantum computing
    and create a summary report.
    """
    
    # Execute task
    result = await agent.run(task)
    print(result)

# Run the example
asyncio.run(execute_research())

Multi-Agent Collaboration

Create multiple agents that work together:

from agentic_fleet.agents import AgentGroup

async def collaborative_task():
    # Create agents
    researcher = Agent(
        name="researcher",
        tools=[WebSearch()]
    )
    
    writer = Agent(
        name="writer",
        tools=[FileReader()]
    )
    
    # Create agent group
    group = AgentGroup([researcher, writer])
    
    # Execute collaborative task
    result = await group.collaborate(
        task="Research and write about AI advances"
    )
    print(result)

# Run the example
asyncio.run(collaborative_task())

Web Application

Create a simple web application with FastAPI:

from fastapi import FastAPI
from agentic_fleet import Agent
from agentic_fleet.integrations.fastapi import AgentRouter

# Create FastAPI app
app = FastAPI()

# Create agent
agent = Agent(name="web_assistant")

# Create router
router = AgentRouter(agent)

# Add routes
app.include_router(router)

# Run with: uvicorn app:app --reload

Chat Interface

Create a chat interface with Chainlit:

import chainlit as cl
from agentic_fleet import Agent
from agentic_fleet.integrations.chainlit import ChainlitUI

@cl.on_chat_start
async def start():
    # Create agent
    agent = Agent(name="chat_assistant")
    
    # Create UI
    ui = ChainlitUI(agent)
    
    # Store in session
    cl.user_session.set("ui", ui)

@cl.on_message
async def main(message: str):
    # Get UI
    ui = cl.user_session.get("ui")
    
    # Process message
    response = await ui.process_message(message)
    
    # Send response
    await cl.Message(
        content=response.content
    ).send()

# Run with: chainlit run app.py

Custom Tool

Create and use a custom tool:

from agentic_fleet.tools import BaseTool

class WeatherTool(BaseTool):
    name = "weather_tool"
    description = "Get weather information"
    
    async def _run(self, location: str) -> dict:
        # Implement weather lookup
        weather = await self.get_weather(location)
        return {"weather": weather}
    
    async def get_weather(self, location: str):
        # Implement actual weather API call
        return {"temperature": 20, "condition": "sunny"}

async def weather_example():
    # Create agent with custom tool
    agent = Agent(
        name="weather_assistant",
        tools=[WeatherTool()]
    )
    
    # Use tool
    response = await agent.run(
        "What's the weather in London?"
    )
    print(response)

# Run the example
asyncio.run(weather_example())

Complete Example

Here’s a complete example combining multiple features:

from agentic_fleet import Agent, AgentConfig
from agentic_fleet.tools import WebSearch, FileReader
from agentic_fleet.memory import Memory

async def complete_example():
    # Create configuration
    config = AgentConfig(
        name="assistant",
        model="gpt-4",
        temperature=0.7,
        max_tokens=2000
    )
    
    # Create memory
    memory = Memory(storage_type="redis")
    
    # Create tools
    tools = [WebSearch(), FileReader()]
    
    # Create agent
    agent = Agent(
        config=config,
        memory=memory,
        tools=tools
    )
    
    # Execute tasks
    tasks = [
        "Research quantum computing",
        "Summarize findings",
        "Create report"
    ]
    
    for task in tasks:
        result = await agent.run(task)
        print(f"Task: {task}")
        print(f"Result: {result}\n")
    
    # Clean up
    await agent.cleanup()

# Run the complete example
if __name__ == "__main__":
    asyncio.run(complete_example())

Next Steps

  1. Explore more examples
  2. Read the API documentation
  3. Join our Discord community
  4. Contribute to AgenticFleet