Complete API documentation for Qilbee Mycelial Network Python SDK v0.2.0.
- MycelialClient
- Nutrient
- Outcome
- Sensitivity
- Context
- QMNSettings
- Control Plane Methods (New in v0.2.0)
- Hyphal Memory Methods (New in v0.2.0)
The main client for interacting with the Qilbee Mycelial Network.
class MycelialClient:
def __init__(self, settings: QMNSettings)Parameters:
settings(QMNSettings): Configuration settings for the client
Example:
from qilbee_mycelial_network import MycelialClient, QMNSettings
settings = QMNSettings(
api_key="qmn_your_key",
api_base_url="https://api.qilbee.io"
)
client = MycelialClient(settings)Create client from environment variables.
@classmethod
async def create_from_env(cls) -> MycelialClientReturns:
MycelialClient: Configured client instance
Environment Variables:
QMN_API_KEY(required): Your API keyQMN_API_BASE_URL: API endpoint (default: https://api.qilbee.io)QMN_PREFERRED_REGION: Preferred regionQMN_TRANSPORT: Transport protocol (http/grpc/quic)QMN_DEBUG: Enable debug mode
Example:
import asyncio
from qilbee_mycelial_network import MycelialClient
async def main():
async with MycelialClient.create_from_env() as client:
# Use client
pass
asyncio.run(main())Broadcast a nutrient to the mycelial network.
async def broadcast(
self,
nutrient: Nutrient,
*,
timeout_sec: Optional[int] = None
) -> BroadcastResponseParameters:
nutrient(Nutrient): The nutrient to broadcasttimeout_sec(Optional[int]): Request timeout in seconds
Returns:
BroadcastResponse: Response containing broadcast status and metadata
Raises:
APIError: If the broadcast failsTimeoutError: If the request times outValidationError: If the nutrient is invalid
Example:
from qilbee_mycelial_network import Nutrient, Sensitivity
nutrient = Nutrient.seed(
summary="Database optimization query",
embedding=[0.1] * 1536,
snippets=["SELECT * FROM large_table"],
tool_hints=["db.analyze"],
sensitivity=Sensitivity.INTERNAL
)
response = await client.broadcast(nutrient)
print(f"Broadcast ID: {response.broadcast_id}")Collect contexts from the network matching the demand embedding.
async def collect(
self,
demand_embedding: List[float],
*,
window_ms: int = 300,
top_k: int = 5,
diversify: bool = True,
min_similarity: float = 0.7,
timeout_sec: Optional[int] = None
) -> ContextParameters:
demand_embedding(List[float]): Query embedding vector (1536-dim)window_ms(int): Time window in milliseconds (default: 300)top_k(int): Maximum number of results (default: 5)diversify(bool): Apply MMR diversity (default: True)min_similarity(float): Minimum cosine similarity (default: 0.7)timeout_sec(Optional[int]): Request timeout
Returns:
Context: Collection of matching contexts with trace ID
Example:
contexts = await client.collect(
demand_embedding=get_embedding("database performance"),
window_ms=500,
top_k=10,
diversify=True,
min_similarity=0.75
)
for content in contexts.contents:
print(f"Agent: {content['agent_id']}")
print(f"Summary: {content['summary']}")
print(f"Similarity: {content['score']}")Record task outcome for reinforcement learning.
async def record_outcome(
self,
trace_id: str,
outcome: Outcome,
*,
metadata: Optional[Dict[str, Any]] = None,
timeout_sec: Optional[int] = None
) -> OutcomeResponseParameters:
trace_id(str): Trace ID from collect() responseoutcome(Outcome): Task outcome with scoremetadata(Optional[Dict]): Additional metadatatimeout_sec(Optional[int]): Request timeout
Returns:
OutcomeResponse: Confirmation of outcome recording
Example:
from qilbee_mycelial_network import Outcome
# Successful task
await client.record_outcome(
trace_id=contexts.trace_id,
outcome=Outcome.with_score(0.92),
metadata={"task_type": "optimization", "duration_ms": 1250}
)
# Per-hop outcomes (v0.2.0) - granular per-agent feedback
await client.record_outcome(
trace_id=contexts.trace_id,
outcome=Outcome.with_hop_scores(
score=0.85,
hop_outcomes={"agent-1": 0.9, "agent-2": 0.6}
)
)
# Failed task
await client.record_outcome(
trace_id=contexts.trace_id,
outcome=Outcome.with_score(0.0),
metadata={"error": "timeout"}
)Store persistent knowledge in the hyphal memory vector database.
async def hyphal_store(
self,
agent_id: str,
kind: str,
content: Dict[str, Any],
embedding: List[float],
*,
quality: float = 0.5,
sensitivity: str = "internal",
metadata: Optional[Dict[str, Any]] = None,
timeout_sec: Optional[int] = None
) -> StoreResponseParameters:
agent_id(str): Agent identifierkind(str): Memory type (insight, snippet, decision, preference)content(Dict): Memory content payloadembedding(List[float]): 1536-dim vector representationquality(float): Quality score 0.0-1.0sensitivity(str): Sensitivity levelmetadata(Optional[Dict]): Additional metadatatimeout_sec(Optional[int]): Request timeout
Example:
await client.hyphal_store(
agent_id="agent-001",
kind="insight",
content={"finding": "Important discovery about performance"},
embedding=[0.1] * 1536,
quality=0.9,
sensitivity="internal"
)Search stored memories using semantic similarity.
async def hyphal_search(
self,
embedding: List[float],
*,
top_k: int = 10,
min_quality: float = 0.5,
filters: Optional[Dict[str, str]] = None,
timeout_sec: Optional[int] = None
) -> SearchResponseParameters:
embedding(List[float]): Query embedding vector (1536-dim)top_k(int): Maximum results (default: 10)min_quality(float): Minimum quality score (default: 0.5)filters(Optional[Dict]): Filters (e.g.,{"kind": "insight"})timeout_sec(Optional[int]): Request timeout
Example:
results = await client.hyphal_search(
embedding=[0.1] * 1536,
top_k=10,
filters={"kind": "insight"}
)
for result in results.results:
print(f"Content: {result.content}, Score: {result.similarity}")Get usage metrics for the current tenant.
async def get_usage(
self,
*,
timeout_sec: Optional[int] = None
) -> UsageResponseReturns:
UsageResponse: Usage metrics including broadcast count, collect count, and storage usage
Example:
usage = await client.get_usage()
print(f"Broadcasts: {usage.broadcasts}")
print(f"Collections: {usage.collections}")Register an agent with the network.
async def register_agent(
self,
agent_id: str,
profile_embedding: List[float],
capabilities: List[str],
*,
metadata: Optional[Dict[str, Any]] = None,
timeout_sec: Optional[int] = None
) -> AgentResponseParameters:
agent_id(str): Unique agent identifierprofile_embedding(List[float]): Agent profile vector (1536-dim)capabilities(List[str]): Agent capabilities/skillsmetadata(Optional[Dict]): Additional agent metadatatimeout_sec(Optional[int]): Request timeout
Returns:
AgentResponse: Agent registration confirmation
Example:
await client.register_agent(
agent_id="code-reviewer-01",
profile_embedding=get_embedding("code review security performance"),
capabilities=[
"code.review",
"security.audit",
"performance.analyze"
],
metadata={
"languages": ["python", "javascript", "go"],
"expertise": ["security", "performance"],
"version": "2.0.1"
}
)Check client and service health.
async def health_check(
self,
*,
timeout_sec: Optional[int] = 5
) -> HealthResponseReturns:
HealthResponse: Health status of services
Example:
health = await client.health_check()
print(f"Status: {health.status}")
print(f"Latency: {health.latency_ms}ms")Data model for nutrients flowing through the network.
class Nutrient(BaseModel):
summary: str
embedding: List[float]
snippets: Optional[List[str]] = None
tool_hints: Optional[List[str]] = None
sensitivity: Sensitivity = Sensitivity.INTERNAL
ttl_sec: int = 300
max_hops: int = 3
metadata: Optional[Dict[str, Any]] = NoneFields:
summary(str): Brief description of nutrient contentembedding(List[float]): 1536-dimension vector representationsnippets(Optional[List[str]]): Code snippets or text fragmentstool_hints(Optional[List[str]]): Suggested tools/capabilitiessensitivity(Sensitivity): Data sensitivity levelttl_sec(int): Time-to-live in secondsmax_hops(int): Maximum network hopsmetadata(Optional[Dict]): Additional data
Create a new nutrient instance.
@classmethod
def seed(
cls,
summary: str,
embedding: List[float],
**kwargs
) -> NutrientExample:
from qilbee_mycelial_network import Nutrient, Sensitivity
nutrient = Nutrient.seed(
summary="Database query optimization needed",
embedding=[0.1] * 1536,
snippets=[
"SELECT * FROM users WHERE created_at > '2024-01-01'",
"Execution time: 2.3s"
],
tool_hints=["db.analyze", "query.optimize"],
sensitivity=Sensitivity.INTERNAL,
ttl_sec=180,
max_hops=5,
metadata={"database": "postgresql", "table": "users"}
)Task outcome for reinforcement learning.
class Outcome(BaseModel):
score: float
details: Optional[str] = None
hop_outcomes: Optional[Dict[str, float]] = NoneFields:
score(float): Success score between 0.0 and 1.0details(Optional[str]): Additional outcome detailshop_outcomes(Optional[Dict[str, float]]): Per-agent scores for granular RL (New in v0.2.0)
Create outcome with score.
@classmethod
def with_score(
cls,
score: float,
details: Optional[str] = None
) -> OutcomeParameters:
score(float): Success score (0.0 to 1.0)details(Optional[str]): Outcome description
Example:
from qilbee_mycelial_network import Outcome
# Successful outcome
success = Outcome.with_score(0.95, "Task completed successfully")
# Partial success
partial = Outcome.with_score(0.6, "Task completed with warnings")
# Failure
failure = Outcome.with_score(0.0, "Task failed: timeout")Create outcome with per-agent scores for granular reinforcement learning.
@classmethod
def with_hop_scores(
cls,
score: float,
hop_outcomes: Dict[str, float],
details: Optional[str] = None
) -> OutcomeParameters:
score(float): Overall success score (0.0 to 1.0)hop_outcomes(Dict[str, float]): Map of agent_id to individual scoredetails(Optional[str]): Outcome description
Example:
from qilbee_mycelial_network import Outcome
# Per-hop feedback - reward useful agents more
outcome = Outcome.with_hop_scores(
score=0.85,
hop_outcomes={
"agent-researcher-01": 0.95, # Very helpful
"agent-coder-03": 0.8, # Helpful
"agent-reviewer-02": 0.4 # Less helpful
}
)
await client.record_outcome(trace_id=contexts.trace_id, outcome=outcome)Enumeration of data sensitivity levels.
class Sensitivity(str, Enum):
PUBLIC = "PUBLIC"
INTERNAL = "INTERNAL"
CONFIDENTIAL = "CONFIDENTIAL"
SECRET = "SECRET"Levels:
PUBLIC: Public information, no restrictionsINTERNAL: Internal use, company-wide accessCONFIDENTIAL: Confidential data, restricted accessSECRET: Secret data, highly restricted
Example:
from qilbee_mycelial_network import Sensitivity, Nutrient
# Public nutrient
public_nutrient = Nutrient.seed(
summary="Public API documentation",
embedding=[...],
sensitivity=Sensitivity.PUBLIC
)
# Secret nutrient
secret_nutrient = Nutrient.seed(
summary="Authentication credentials",
embedding=[...],
sensitivity=Sensitivity.SECRET
)Collection of contexts from the network.
class Context(BaseModel):
trace_id: str
contents: List[Dict[str, Any]]
metadata: Dict[str, Any]Fields:
trace_id(str): Unique trace identifier for outcome recordingcontents(List[Dict]): Matched contextsmetadata(Dict): Collection metadata (timing, stats, etc.)
Content Fields:
agent_id(str): Source agent identifiersummary(str): Content summarydata(Any): Context datascore(float): Similarity scoretimestamp(str): ISO 8601 timestamp
Example:
contexts = await client.collect(demand_embedding=[...])
print(f"Trace ID: {contexts.trace_id}")
print(f"Found {len(contexts.contents)} contexts")
for content in contexts.contents:
print(f"Agent: {content['agent_id']}")
print(f"Score: {content['score']:.3f}")
print(f"Summary: {content['summary']}")
print(f"Data: {content['data']}")Configuration settings for MycelialClient.
class QMNSettings(BaseModel):
api_key: str
api_base_url: str = "https://api.qilbee.io"
preferred_region: Optional[str] = None
transport: str = "http"
timeout_sec: int = 30
max_retries: int = 3
debug: bool = FalseFields:
api_key(str): QMN API key (required)api_base_url(str): API endpoint URLpreferred_region(Optional[str]): Preferred region (us-east-1, etc.)transport(str): Transport protocol (http/grpc/quic)timeout_sec(int): Default request timeoutmax_retries(int): Maximum retry attemptsdebug(bool): Enable debug logging
Example:
from qilbee_mycelial_network import QMNSettings, MycelialClient
# Production settings
prod_settings = QMNSettings(
api_key="qmn_prod_key",
api_base_url="https://api.qilbee.io",
preferred_region="us-east-1",
transport="grpc",
timeout_sec=30,
max_retries=3,
debug=False
)
# Development settings
dev_settings = QMNSettings(
api_key="qmn_dev_key",
api_base_url="http://localhost:8200",
transport="http",
timeout_sec=60,
debug=True
)
async with MycelialClient(prod_settings) as client:
# Production client
passException
├── QMNError (base exception)
│ ├── APIError (API request failed)
│ ├── ValidationError (invalid input)
│ ├── AuthenticationError (invalid API key)
│ ├── RateLimitError (rate limit exceeded)
│ └── TimeoutError (request timeout)
from qilbee_mycelial_network import (
MycelialClient,
APIError,
AuthenticationError,
RateLimitError,
TimeoutError
)
async def robust_broadcast(client, nutrient):
try:
response = await client.broadcast(nutrient)
return response
except AuthenticationError:
print("Invalid API key")
except RateLimitError as e:
print(f"Rate limited. Retry after: {e.retry_after}s")
except TimeoutError:
print("Request timed out")
except APIError as e:
print(f"API error: {e.message}")The SDK is fully typed with Python type hints:
from typing import List, Optional, Dict, Any
from qilbee_mycelial_network import MycelialClient, Nutrient, Context
async def process_task(
client: MycelialClient,
query: str,
embedding: List[float]
) -> Optional[Dict[str, Any]]:
"""Process task with type safety."""
contexts: Context = await client.collect(
demand_embedding=embedding,
top_k=5
)
if not contexts.contents:
return None
return {
"trace_id": contexts.trace_id,
"results": contexts.contents
}- Broadcast: 100 requests/min
- Collect: 200 requests/min
- Record Outcome: 500 requests/min
- Register Agent: 10 requests/min
Rate limit headers:
X-RateLimit-Limit: Request limitX-RateLimit-Remaining: Remaining requestsX-RateLimit-Reset: Reset timestamp (Unix epoch)
For methods returning large result sets:
contexts = await client.collect(
demand_embedding=[...],
top_k=100, # Max 100 results per request
offset=0 # Pagination offset
)
# Get next page
next_contexts = await client.collect(
demand_embedding=[...],
top_k=100,
offset=100
)Register webhooks for asynchronous notifications:
await client.register_webhook(
url="https://your-domain.com/webhook",
events=["nutrient.received", "outcome.recorded"],
secret="your_webhook_secret"
)The SDK now provides full control plane access for managing tenants, API keys, and policies.
# Create a new tenant (admin only)
await client.create_tenant(tenant_id="new-org", name="New Org", plan_tier="pro")
# Get tenant details
tenant = await client.get_tenant(tenant_id="new-org")
# List tenants (admin only)
tenants = await client.list_tenants(status_filter="active")
# Update tenant
await client.update_tenant(tenant_id="new-org", name="Updated Org", plan_tier="enterprise")
# Delete tenant (admin only)
await client.delete_tenant(tenant_id="new-org")# Create a new API key
key = await client.create_key(name="prod-key", scopes=["*"])
print(f"Key: {key.api_key}") # Store securely - shown only once
# Validate a key
result = await client.validate_key(api_key="qmn_...")
# List keys for tenant
keys = await client.list_keys()
# Revoke a key
await client.revoke_key(key_id="key-uuid")# Evaluate a policy
result = await client.evaluate_policy(
policy_type="rbac",
context={"role": "admin", "resource": "tenants"}
)
# Create a policy
await client.create_policy(
name="Block Confidential Broadcasts",
policy_type="dlp",
rules={"sensitivity": "confidential", "action": "deny"}
)
# List policies
policies = await client.list_policies()See hyphal_store() and hyphal_search() above under Methods.
- Examples: GitHub Examples
- Tutorials: qilbee.io/docs/tutorials
- FAQ: qilbee.io/docs/faq
- Support: contact@aicube.ca