Cadence SDK - To building custom AI agent plugins for Cadence AI Framework
Project description
Cadence SDK
A comprehensive SDK for building custom AI agent plugins for the Cadence Framework.
Overview
The Cadence SDK provides the tools and interfaces needed to create powerful, extensible AI agents that integrate seamlessly with the Cadence multi-agent framework. Build agents with custom tools, sophisticated reasoning capabilities, and domain-specific knowledge.
Features
- Agent Framework: Create intelligent agents with custom behavior
- Tool System: Build and integrate custom tools for agents
- Plugin Management: Easy plugin discovery and registration
- Type Safety: Full TypeScript/Python type support
- Extensible: Plugin-based architecture for easy extension
Installation
pip install cadence-sdk
Quick Start
Key Imports
# Core classes
from cadence_sdk import BaseAgent, BasePlugin, PluginMetadata
from cadence_sdk.tools import Tool
from cadence_sdk import tool, register_plugin
# Registry functions
from cadence_sdk import discover_plugins, register_plugin
Creating a Simple Agent
from cadence_sdk.base.agent import BaseAgent
from cadence_sdk.base.metadata import PluginMetadata
from cadence_sdk.tools import Tool
class CalculatorAgent(BaseAgent):
def __init__(self, metadata: PluginMetadata):
super().__init__(metadata)
def get_tools(self):
from .tools import CalculatorTool
return [CalculatorTool()]
def get_system_prompt(self) -> str:
return "You are a calculator agent that helps with mathematical calculations."
class CalculatorTool(Tool):
name = "calculate"
description = "Perform mathematical calculations"
def execute(self, expression: str) -> str:
try:
result = eval(expression)
return str(result)
except Exception as e:
return f"Error: {str(e)}"
Plugin Structure
my_plugin/
├── __init__.py # Plugin registration
├── plugin.py # Main plugin class (BasePlugin)
├── agent.py # Agent implementation (BasePluginAgent)
└── tools.py # Tool functions and classes
Required Files:
__init__.py: Must callregister_plugin(YourPlugin)plugin.py: Must implementBasePluginwithget_metadata()andcreate_agent()agent.py: Must implementBaseAgentwithget_tools()andget_system_prompt()tools.py: Contains the actual tool implementations
Plugin Registration
from cadence_sdk.base.plugin import BasePlugin
from cadence_sdk.base.metadata import PluginMetadata
class CalculatorPlugin(BasePlugin):
@staticmethod
def get_metadata() -> PluginMetadata:
return PluginMetadata(
name="calculator",
version="1.0.1",
description="Mathematical calculation plugin",
capabilities=["mathematics", "calculations"],
llm_requirements={
"provider": "openai",
"model": "gpt-4",
"temperature": 0.1
},
agent_type="specialized",
dependencies=[]
)
@staticmethod
def create_agent():
from .agent import CalculatorAgent
return CalculatorAgent(CalculatorPlugin.get_metadata())
Configuration
Plugin Registration
To make your plugin discoverable by the Cadence framework, you need to register it in your plugin's __init__.py:
# plugins/src/cadence_example_plugins/my_plugin/__init__.py
from cadence_sdk import register_plugin
from .plugin import MyPlugin
# Register on import
register_plugin(MyPlugin)
Environment Variables
# Set plugin directories (single path or JSON list)
export CADENCE_PLUGINS_DIR="./plugins/src/cadence_plugins"
# Or multiple directories as JSON array
export CADENCE_PLUGINS_DIR='["/path/to/plugins", "/another/path"]'
# Plugin limits (configured in main application)
export CADENCE_MAX_AGENT_HOPS=25
export CADENCE_MAX_TOOL_HOPS=50
export CADENCE_GRAPH_RECURSION_LIMIT=50
Plugin Discovery
The SDK automatically discovers plugins from:
- Environment packages
- Directory paths
- Custom registries
Advanced Usage
Custom Tool Decorators
from cadence_sdk.tools.decorators import tool
@tool
def weather_tool(city: str) -> str:
"""Get weather information for a city."""
# Implementation here
return f"Weather for {city}: Sunny, 72°F"
# Tools are automatically registered when using the decorator
weather_tools = [weather_tool]
Agent State Management
from cadence_sdk.types.state import AgentState
class StatefulAgent(BaseAgent):
def __init__(self, metadata: PluginMetadata):
super().__init__(metadata)
def get_tools(self):
return []
def get_system_prompt(self) -> str:
return "You are a stateful agent that maintains context."
def should_continue(self, state: AgentState) -> str:
# Access conversation history
history = state.conversation_history
# Update state if needed
if len(history) > 10:
return "back" # Return to coordinator
return "continue" # Continue processing
Plugin Registry
from cadence_sdk.registry.plugin_registry import PluginRegistry
# Get plugin registry
registry = PluginRegistry()
# Register custom plugin
registry.register(CalculatorPlugin())
# Discover plugins
plugins = registry.discover()
Examples
Math Agent
from cadence_sdk.base.agent import BaseAgent
from cadence_sdk.base.metadata import PluginMetadata
from cadence_sdk.tools import Tool
class MathAgent(BaseAgent):
def __init__(self, metadata: PluginMetadata):
super().__init__(metadata)
def get_tools(self):
from .tools import CalculatorTool
return [CalculatorTool()]
def get_system_prompt(self) -> str:
return "You are a math agent specialized in mathematical operations. Use the calculator tool for calculations."
class CalculatorTool(Tool):
name = "calculator"
description = "Perform mathematical calculations"
def execute(self, expression: str) -> str:
try:
result = eval(expression)
return f"Result: {result}"
except:
return "Invalid expression"
Search Agent
from cadence_sdk.base.agent import BaseAgent
from cadence_sdk.base.metadata import PluginMetadata
from cadence_sdk.tools import Tool
import requests
class SearchAgent(BaseAgent):
def __init__(self, metadata: PluginMetadata):
super().__init__(metadata)
def get_tools(self):
from .tools import WebSearchTool
return [WebSearchTool()]
def get_system_prompt(self) -> str:
return "You are a search agent that helps users find information on the web. Use the web search tool to perform searches."
class WebSearchTool(Tool):
name = "web_search"
description = "Search the web for information"
def execute(self, query: str) -> str:
# Implementation would go here
return f"Searching for: {query}"
Development
Setting up Development Environment
# Clone the main repository
git clone https://github.com/jonaskahn/cadence.git
cd cadence
# Install SDK dependencies
cd sdk
poetry install
# Run tests
poetry run pytest
# Format code
poetry run black src/
poetry run isort src/
Testing
# Run all tests
poetry run pytest
# Run with coverage
poetry run pytest --cov=src/cadence_sdk
# Run specific test categories
poetry run pytest -m "unit"
poetry run pytest -m "integration"
Contributing
We welcome contributions! Please see our Contributing Guide for details.
Development Setup
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
- Documentation: Read the Docs
- Issues: GitHub Issues
- Discussions: GitHub Discussions
Built with ❤️ for the Cadence AI community
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cadence_sdk-1.0.1.tar.gz.
File metadata
- Download URL: cadence_sdk-1.0.1.tar.gz
- Upload date:
- Size: 24.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.4 CPython/3.13.5 Darwin/24.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4216b7dd4e9dce06a6b211105b5f8bdd30c4637a5bdd33c23f0f8a60adfd918d
|
|
| MD5 |
6953938436ee0f154efe22e1025a21c2
|
|
| BLAKE2b-256 |
e8d0f73c582a2f60114de432880958bbef508060f2e589985dcece708d00a578
|
File details
Details for the file cadence_sdk-1.0.1-py3-none-any.whl.
File metadata
- Download URL: cadence_sdk-1.0.1-py3-none-any.whl
- Upload date:
- Size: 31.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.4 CPython/3.13.5 Darwin/24.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a288a439338a5e51f464eca444ea0d6c972e1ed1b1ca173335e673a8eb4cb4b9
|
|
| MD5 |
2f02dc2a10af5964c895cf1780bf2931
|
|
| BLAKE2b-256 |
dd9647e3840a15d0534e759864562660af5ed171331b7845a4cc54498e857bb6
|