An SDK for building and deploying AI agents with GreenNode AgentBase
Project description
GreenNode AgentBase SDK
A Python SDK for building and deploying AI agents with GreenNode AgentBase runtime.
Overview
GreenNode AgentBase SDK provides a runtime framework for deploying AI agents with support for:
- HTTP endpoint handling for agent invocations
- Health status monitoring and ping endpoints
- Async task tracking
- Request context management
- Streaming responses
- Unified error handling
Installation
pip install greennode-agentbase
Quick Start
from greennode_agentbase import GreenNodeAgentBaseApp
# Create the application
app = GreenNodeAgentBaseApp()
# Define your agent handler
@app.entrypoint
def my_agent(payload: dict):
"""Your agent logic here."""
query = payload.get("query", "")
# Process the query with your agent
return {"response": f"Processed: {query}"}
# Run the server
if __name__ == "__main__":
app.run(port=8080)
Usage
Basic Agent Handler
from greennode_agentbase import GreenNodeAgentBaseApp
app = GreenNodeAgentBaseApp()
@app.entrypoint
def simple_agent(payload: dict) -> dict:
"""Simple agent that echoes the input."""
return {"echo": payload}
Handler with Request Context
from greennode_agentbase import GreenNodeAgentBaseApp, RequestContext
app = GreenNodeAgentBaseApp()
@app.entrypoint
def contextual_agent(payload: dict, context: RequestContext) -> dict:
"""Agent that uses request context."""
session_id = context.session_id
headers = context.request_headers or {}
return {
"result": payload,
"session_id": session_id,
"authorization": headers.get("Authorization"),
}
Async Agent Handler
import asyncio
from greennode_agentbase import GreenNodeAgentBaseApp
app = GreenNodeAgentBaseApp()
@app.entrypoint
async def async_agent(payload: dict) -> dict:
"""Async agent handler."""
# Simulate async work
await asyncio.sleep(0.1)
return {"result": "async processing complete"}
Streaming Responses
from greennode_agentbase import GreenNodeAgentBaseApp
app = GreenNodeAgentBaseApp()
@app.entrypoint
def streaming_agent(payload: dict):
"""Agent that streams responses."""
for i in range(5):
yield {"chunk": i, "data": f"chunk_{i}"}
Custom Ping Handler
from greennode_agentbase import GreenNodeAgentBaseApp, PingStatus
app = GreenNodeAgentBaseApp()
@app.ping
def custom_health_check() -> PingStatus:
"""Custom health check logic."""
# Check your system health
if system_is_busy():
return PingStatus.HEALTHY_BUSY
return PingStatus.HEALTHY
Async Task Tracking
from greennode_agentbase import GreenNodeAgentBaseApp
app = GreenNodeAgentBaseApp()
@app.async_task
async def background_processing():
"""Long-running background task."""
# This task will be tracked for health monitoring
await process_large_dataset()
Error Handling
All SDK errors inherit from GreenNodeAgentBaseError:
from greennode_agentbase import (
GreenNodeAgentBaseError,
GreenNodeValidationError,
GreenNodeRuntimeError,
GreenNodeRequestError,
GreenNodeConfigurationError,
)
try:
# Your code here
pass
except GreenNodeValidationError as e:
print(f"Validation error: {e.message}")
print(f"Details: {e.details}")
except GreenNodeRuntimeError as e:
print(f"Runtime error: {e.message}")
except GreenNodeAgentBaseError as e:
print(f"SDK error: {e.message}")
Command-line interface (CLI)
The greennode CLI provides deploy, memory, and runtime management. Use greennode --help and greennode <group> --help for details.
CLI hierarchy
greennode
├── deploy
│ └── run Deploy agent (build, push, create runtime). Use -o id to print only the runtime id.
├── memory
│ ├── create Create a memory
│ ├── list List memories
│ ├── get Get a memory by ID
│ └── ... (other memory subcommands)
└── runtime
├── list List runtimes
├── get <id> Get a runtime by ID
├── patch <id> Update a runtime (image, flavor, env, command, args)
└── endpoints
├── list <runtime-id> List endpoints for a runtime
├── create <runtime-id> Create an endpoint
├── update <runtime-id> <endpoint-id> Update endpoint (e.g. --version)
└── delete <runtime-id> <endpoint-id> Delete an endpoint
Best practices
- Config precedence: Values are resolved in order: environment variables →
.greennode.json(forGREENNODE_CLIENT_ID,GREENNODE_CLIENT_SECRET,GREENNODE_ACCESS_CONTROL_NAME, registry vars, etc.). Use.greennode.jsonfor non-sensitive defaults and environment variables for secrets. - When to use which: Use
greennode deploy runfor a full deploy (build, push, create runtime). Usegreennode runtime list,get,patchandgreennode runtime endpoints ...to manage runtimes and endpoints without redeploying. - Scripting: After
greennode deploy run, the runtime id is printed on its own line. Usegreennode deploy run -o idto print only the runtime id for scripts.
API Reference
GreenNodeAgentBaseApp
Main application class for deploying agents.
Methods
entrypoint(func)- Decorator to register the main agent handlerping(func)- Decorator to register a custom ping/health handlerasync_task(func)- Decorator to track async tasksrun(port=8080, host=None)- Start the serverget_current_ping_status()- Get current health statusforce_ping_status(status)- Force a specific ping statusadd_async_task(name, metadata=None)- Manually track an async taskcomplete_async_task(task_id)- Mark an async task as complete
RequestContext
Request context model containing request metadata.
Attributes
session_id- Optional session identifierrequest_headers- Optional dictionary of request headersrequest- Underlying Starlette request object
GreenNodeAgentBaseContext
Context manager for request-scoped data.
Methods
set_request_context(request_id, session_id=None)- Set request contextget_request_id()- Get current request IDget_session_id()- Get current session IDset_workload_access_token(token)- Set access tokenget_workload_access_token()- Get access tokenset_request_headers(headers)- Set request headersget_request_headers()- Get request headers
PingStatus
Enum for health status values:
HEALTHY- Agent is healthy and readyHEALTHY_BUSY- Agent is healthy but processing requests
HTTP Endpoints
POST /invocations
Main endpoint for agent invocations.
Request:
{
"prompt": "your input here"
}
Response:
{
"result": "agent output"
}
GET /health
Health check endpoint.
Response:
{
"status": "Healthy",
"time_of_last_update": 1234567890
}
Error Handling
All errors in the SDK inherit from GreenNodeAgentBaseError:
GreenNodeValidationError- Input validation errorsGreenNodeRuntimeError- Runtime execution errorsGreenNodeConfigurationError- Configuration errorsGreenNodeRequestError- HTTP request errors
All errors include:
message- Error messagedetails- Optional error details dictionarycause- Optional underlying exception
Development
Setup
# Install development dependencies
pip install -e ".[dev]"
# Run tests
pytest
# Run linting
ruff check src tests
# Run type checking
mypy src
Testing
# Run all tests
pytest
# Run with coverage
pytest --cov=src --cov-report=html
# Run specific test file
pytest tests/greennode_agentbase/runtime/test_app.py
License
Apache License 2.0 - see LICENSE.txt for details.
Contributing
Contributions are welcome! Please ensure:
- All tests pass
- Code follows the style guidelines (ruff, mypy)
- New features include tests
- Documentation is updated
Support
For issues and questions, please use the project's issue tracker.
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 greennode_agentbase-1.0.1.tar.gz.
File metadata
- Download URL: greennode_agentbase-1.0.1.tar.gz
- Upload date:
- Size: 59.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6317e3530c46629b61cbfc2e2a4631cb69917fd8800b4bf99a11bc98a458b4b5
|
|
| MD5 |
83bf7fd723ce0216f4e6fc6c18e672de
|
|
| BLAKE2b-256 |
23106277a69241ab3bcae53587a1ee99211f6b0989697f800f73ae1ebd1fe6a1
|
Provenance
The following attestation bundles were made for greennode_agentbase-1.0.1.tar.gz:
Publisher:
publish.yml on vngcloud/greennode-agentbase-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
greennode_agentbase-1.0.1.tar.gz -
Subject digest:
6317e3530c46629b61cbfc2e2a4631cb69917fd8800b4bf99a11bc98a458b4b5 - Sigstore transparency entry: 899671582
- Sigstore integration time:
-
Permalink:
vngcloud/greennode-agentbase-sdk@04973884b3939203af5e29a87e08811518c08362 -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/vngcloud
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@04973884b3939203af5e29a87e08811518c08362 -
Trigger Event:
push
-
Statement type:
File details
Details for the file greennode_agentbase-1.0.1-py3-none-any.whl.
File metadata
- Download URL: greennode_agentbase-1.0.1-py3-none-any.whl
- Upload date:
- Size: 73.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c8122729698fefea894dfef313d73206f0bd8f2f84c60f27b8022c1cf3d8e27c
|
|
| MD5 |
8e7050425dc6ef79528c443a9240ae15
|
|
| BLAKE2b-256 |
c82dc05357ae7dbd2e99603b224b7e852b87c7289e6ed505dee0754704a8b5aa
|
Provenance
The following attestation bundles were made for greennode_agentbase-1.0.1-py3-none-any.whl:
Publisher:
publish.yml on vngcloud/greennode-agentbase-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
greennode_agentbase-1.0.1-py3-none-any.whl -
Subject digest:
c8122729698fefea894dfef313d73206f0bd8f2f84c60f27b8022c1cf3d8e27c - Sigstore transparency entry: 899671640
- Sigstore integration time:
-
Permalink:
vngcloud/greennode-agentbase-sdk@04973884b3939203af5e29a87e08811518c08362 -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/vngcloud
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@04973884b3939203af5e29a87e08811518c08362 -
Trigger Event:
push
-
Statement type: