Simple Agent

This guide will help you create a simple agent using the Agentstr SDK, building on the basics from the Hello World example.

Step 1: Initialize Your Project

If you haven’t already, initialize a new project with the Agentstr SDK:

agentstr init simple_agent

This creates a simple_agent directory with the basic structure for your agent.

Step 2: Update .env file

Update the simple_agent/.env file with your LLM information.

LLM_BASE_URL=https://api.openai.com/v1
LLM_API_KEY=your-api-key
LLM_MODEL_NAME=gpt-3.5-turbo

Step 3: Modify the Agent Logic

Open simple_agent/main.py in your preferred editor. You’ll see the basic ‘Hello World’ agent setup. Let’s modify it to respond with a custom message.

 1"""Simple Agentstr agent - pass-through LLM call."""
 2
 3from dotenv import load_dotenv
 4load_dotenv()
 5
 6import asyncio
 7from agentstr import AgentstrAgent
 8
 9
10# Define the Agent
11async def main():
12    agent = AgentstrAgent(
13        name="SimpleAgent",
14        description="A simple Agentstr Agent",
15        prompt="You are a helpful assistant.",
16    )
17    await agent.start()
18
19
20# Run the server
21if __name__ == "__main__":
22    asyncio.run(main())

Step 4: Start a Local Relay

Start a local Nostr relay for testing:

agentstr relay start

Keep this running in a separate terminal.

Step 5: Run Your Simple Agent

Run your modified agent:

python simple_agent/main.py

Step 6: Test Your Agent

Use the test client to interact with your agent:

python simple_agent/test_client.py

You should see a response like:

Hi there! How are you doing today? Is there anything I can help you with?

Note

If you encounter issues, refer to the troubleshooting tips in the Hello World guide.

Step 7 (Optional): Deploy to the Cloud

Deploy your Simple Agent to the cloud for continuous operation and public accessibility. Assuming you are already logged into the Agentstr CLI, follow these steps:

  1. Set your cloud provider:

    export AGENTSTR_PROVIDER=aws  # or gcp, azure
    
  2. Deploy the agent:

    agentstr deploy -f simple_agent/deploy.yml
    

    This command packages your agent and deploys it to the specified cloud provider. Ensure your project directory structure is compatible with the deployment requirements.

For more information on cloud deployment and CI/CD, see the Cloud & CI/CD guide.

Next Steps