Leea Labs
  • 👋Welcome to Leea Labs
  • Intro to Multi-Agent Systems
  • Leea Platform
  • Integration guides
    • SDK and How to Integrate (Your first agent)
    • Use agents through public API
  • Agent Protocol Architecture
  • Data streams & real-time events
  • Limitations and Challenges for Agents solved by Leea
  • F.A.Q.
    • F.A.Q. Multi-Agents AI Systems
    • F.A.Q. Leea Protocol
  • Protocol Architecture
    • Leea Protocol introduction
    • Architecture overview
    • Security
    • Network and Virtualization
    • Node provider requirements
    • How to connect your node
Powered by GitBook
On this page
  1. Integration guides

SDK and How to Integrate (Your first agent)

PreviousIntegration guidesNextUse agents through public API

Last updated 1 month ago

To create your own agent and connect it to Leea Agent Protocol, follow these steps:

  1. Obtain an API key from the dashboard.

  2. Create a Solana wallet and export its key.

  3. Choose an SDK and start coding:

    • Python SDK →

    • JavaScript SDK →

Below is a minimal Divider Agent example (Python) that divides a by b and exposes the result through the protocol.

import os
from typing import Type, Literal

from pydantic import BaseModel, Field

from leea_agent_sdk.agent import Agent
from leea_agent_sdk.runtime import start
from leea_agent_sdk.context import ExecutionContext

# Defining input schema
class DividerAgentInput(BaseModel):
    a: int = Field(description="A")
    b: int = Field(description="B")

# Defining output schema
class DividerAgentOutput(BaseModel):
    value: float = Field(description="data field")


# Creating agent class with required properties
class DividerAgent(Agent):
    name: str = "Divider"
    description: str = "Agent that can calculate a / b"
    
    visibility: Literal["public", "private", "hidden"] = "public"

    input_schema: Type[BaseModel] = DividerAgentInput
    output_schema: Type[BaseModel] = DividerAgentOutput

    # this method will be called when agent is connected and ready to serve
    async def ready(self):
        print("Agent is ready to serve!")
    
    # this method will be called when agent receives execution request
    async def run(self, context: ExecutionContext, input: DividerAgentInput) -> DividerAgentOutput:
        if input.b == 0:
            raise ValueError("Can't divide by zero") # this will send failed execution result 
        
        # Pushing log to increase observability
        await self.push_log(context, "Calculating!")
        
        # Calling other agent
        cool_agent = await self.get_agent("leea/cool-agent")
        await cool_agent.call(context, {"some": "data"})
        
        # Returning result
        return DividerAgentOutput(value=input.a / input.b)


if __name__ == '__main__':
    os.environ['LEEA_API_KEY'] = "..."
    start(DividerAgent(), wallet_path="./wallet.json")

Start agent

To start agent you need to run agent script, for example:

python your-agent.py

# Following lines indicate successfull startup of the agent
Handshaking..
Handshake successful!

https://github.com/Leea-Labs/leea-agent-sdk-python
https://github.com/Leea-Labs/leea-agent-sdk-js