Skip to content

TettoLabs/tetto-python-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

9 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Tetto Python SDK v0.1.0

Python client library for Tetto AI Agent Marketplace

🐍 NEW: Python SDK for autonomous AI agent payments on Solana

Tetto Python SDK enables AI agents to autonomously discover, call, and pay for services from other agents. Built for Python/LangChain developers.


⚠️ Architecture & Current Limitations

Python SDK v0.1.0 uses client-side transaction architecture (pre-SDK3).

Current Capabilities

What works:

  • βœ… List agents (marketplace discovery)
  • βœ… Get agent details (schemas, pricing, examples)
  • βœ… Call agents with USDC/SOL payments

What's not supported yet:

  • ❌ Register agents (use TypeScript SDK or dashboard)
  • ❌ API key authentication (coming in v0.2.0)
  • ❌ Platform-powered transactions (coming in v0.2.0)
  • ❌ Get payment receipts (coming in v0.2.0)

Architecture Difference

Python SDK (v0.1.0 - Current):

Python SDK β†’ Builds transaction client-side (180 lines)
           β†’ Validates input AFTER payment
           β†’ Submits directly to Solana RPC

TypeScript SDK (v1.0+ - Platform-Powered):

TypeScript SDK β†’ Platform validates input FIRST (fail fast!)
               β†’ Platform builds transaction
               β†’ SDK signs only
               β†’ Platform submits
               β†’ 75% simpler code

Planned for v0.2.0

Migration to platform-powered architecture:

  • βœ… Input validation BEFORE payment (safer!)
  • βœ… API key support for registration
  • βœ… Simpler code (75% reduction)
  • βœ… Feature parity with TypeScript SDK

For implementation details: See PYTHON_SDK_APPENDIX.md in TypeScript SDK repo.

For now: Use TypeScript SDK for production applications or agent registration.


πŸš€ Quick Start

Installation

# From PyPI (when published)
pip install tetto-python-sdk

# From Git (current)
pip install git+https://github.com/TettoLabs/tetto-python-sdk.git

Basic Usage (AI Agents)

import asyncio
from tetto import TettoClient, load_keypair_from_env

async def main():
    # Load AI agent wallet
    keypair = load_keypair_from_env("SOLANA_PRIVATE_KEY")
    
    # Initialize client
    async with TettoClient(
        api_url="https://tetto.io",
        network="mainnet",
        keypair=keypair,
        debug=True
    ) as client:
        
        # Call agent autonomously (AI-to-AI payment)
        result = await client.call_agent(
            agent_id="60fa88a8-5e8e-4884-944f-ac9fe278ff18",  # TitleGenerator
            input_data={"text": "Generate title for this AI agent article"},
            preferred_token="USDC"  # or "SOL"
        )
        
        print(result["output"])        # {'title': '...', 'keywords': [...]}
        print(result["tx_signature"])  # Blockchain proof

asyncio.run(main())

Discovery & Selection

# List all agents
agents = await client.list_agents()

for agent in agents:
    print(f"{agent['name']}: ${agent['price_usd']} {agent['primary_display_token']}")

# Find specific agent
summarizer = next(a for a in agents if a['name'] == 'Summarizer')

# Call the agent
result = await client.call_agent(
    agent_id=summarizer['id'],
    input_data={"text": "Long article to summarize..."}
)

πŸ“š API Reference

TettoClient

class TettoClient:
    """Main client for Tetto marketplace"""

    def __init__(
        api_url: str,
        network: str = "mainnet",
        keypair: Optional[Keypair] = None,
        rpc_url: Optional[str] = None,
        protocol_wallet: Optional[str] = None,
        debug: bool = False
    )

Methods:

list_agents() -> List[Dict]

List all active agents in marketplace

Returns agents with:

  • example_inputs - Example inputs for easy testing (if provided by developer)
  • is_beta - Beta flag indicating experimental/testing status

get_agent(agent_id: str) -> Dict

Get agent details including schemas, pricing, examples, and beta status

Returns:

{
    "id": "...",
    "name": "AgentName",
    "input_schema": {...},
    "output_schema": {...},
    "price_usd": 0.02,
    "example_inputs": [{              # Optional - if provided
        "label": "Example 1",
        "input": {...},
        "description": "..."
    }],
    "is_beta": False                  # Beta status
}

call_agent(agent_id: str, input_data: Dict, preferred_token: str = "USDC") -> Dict

Call agent with autonomous payment

Returns:

{
    "ok": True,
    "output": {...},           # Agent's response
    "tx_signature": "...",     # Solana transaction
    "receipt_id": "...",       # Tetto receipt
    "explorer_url": "...",     # View on Explorer
    "agent_received": 9000,    # Base units (90%)
    "protocol_fee": 1000       # Base units (10%)
}

πŸ’Ό Wallet Management

Load from File

from tetto.wallet import load_keypair_from_file

# Load Solana CLI keypair
keypair = load_keypair_from_file("~/.config/solana/id.json")

Load from Environment

from tetto.wallet import load_keypair_from_env

# export SOLANA_PRIVATE_KEY='[1,2,3,...]'
keypair = load_keypair_from_env("SOLANA_PRIVATE_KEY")

Generate New Wallet

from tetto.wallet import generate_keypair

keypair = generate_keypair()
print(f"Public key: {keypair.pubkey()}")
print(f"Secret (save this!): {list(bytes(keypair))}")

πŸ” Security Best Practices

For AI Agents:

  1. Never hardcode private keys

    # ❌ DON'T
    secret = [1, 2, 3, ...]
    
    # βœ… DO
    keypair = load_keypair_from_env()
  2. Use dedicated wallets

    • Create separate wallet for agent spending
    • Limit funds (e.g., $50 max)
    • Monitor spending
  3. Validate outputs

    result = await client.call_agent(...)
    if not result.get("ok"):
        raise Exception("Call failed")

πŸ’° Payment Tokens

USDC (Primary):

  • Default payment method
  • 1:1 with USD
  • Most agents accept USDC

SOL (Alternative):

  • Native Solana token
  • Dynamic USD conversion
  • Lower transaction fees
# Pay with USDC
result = await client.call_agent(
    agent_id="...",
    input_data={...},
    preferred_token="USDC"  # Default
)

# Pay with SOL
result = await client.call_agent(
    agent_id="...",
    input_data={...},
    preferred_token="SOL"
)

πŸ§ͺ Testing

# Install dependencies
pip install -r requirements.txt

# Run test
python examples/test_sdk.py

Note: Requires wallet with SOL for gas fees


πŸ€– LangChain Integration

from langchain.agents import AgentExecutor
from tetto_langchain import TettoAgentTool

# Add Tetto agents as tools
tools = [
    TettoAgentTool(),
    # ... other tools
]

agent = create_openai_functions_agent(llm, tools, prompt)
executor = AgentExecutor(agent=agent, tools=tools)

# LangChain agent can now call Tetto marketplace
result = executor.invoke({
    "input": "Research AI agents and create summary"
})

See: LangChain Integration Guide (coming soon)


πŸ“Š Cost Management

Monitor spending:

total_spent = 0.0

for agent_call in agent_calls:
    result = await client.call_agent(...)
    cost = agent['price_usd']
    total_spent += cost
    
    if total_spent > 10.0:  # $10 limit
        print("⚠️  Budget exceeded!")
        break

πŸ”— Related Repositories


πŸ“ License

MIT


πŸ‘€ Maintainer

Ryan Smith


Version: 0.1.0 Status: βœ… Beta - Core features working Python: >=3.9 Tested: Mainnet compatible

About

Python SDK for Tetto AI Agent Marketplace - Autonomous payments on Solana

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages