# Python SDK - Comprehensive Integration Example
from arkos import ArkosClient, AgentConfig, WorkflowConfig
from arkos.exceptions import ArkosException
import asyncio
from typing import List, Dict, Any
class DevelopmentWorkflowManager:
"""
Comprehensive ARKOS integration for development workflow automation.
Demonstrates advanced SDK usage patterns and best practices.
"""
def __init__(self, api_key: str, environment: str = "production"):
self.client = ArkosClient(
api_key=api_key,
environment=environment,
timeout=30,
retry_attempts=3
)
self.environment = environment
async def setup_project_automation(self, project_config: Dict[str, Any]) -> Dict[str, Any]:
"""
Setup comprehensive automation for a development project.
"""
try:
# Analyze project characteristics
project_analysis = await self.client.analyze_project(
project_path=project_config['path'],
technologies=project_config.get('technologies', []),
team_size=project_config.get('team_size', 5)
)
# Configure agents based on analysis
agent_configs = self._generate_agent_configurations(
project_analysis, project_config
)
# Deploy agent cluster
deployment_result = await self.client.agents.deploy_cluster(
agents=agent_configs,
environment=self.environment,
auto_scale=True
)
# Setup automated workflows
workflows = await self._create_automated_workflows(
project_config, deployment_result
)
# Configure monitoring and alerts
monitoring_config = await self._setup_monitoring(
project_config, deployment_result, workflows
)
return {
'project_analysis': project_analysis,
'deployed_agents': deployment_result,
'workflows': workflows,
'monitoring': monitoring_config,
'estimated_savings': project_analysis.get('estimated_savings', {})
}
except ArkosException as e:
print(f"ARKOS API Error: {e.message}")
raise
except Exception as e:
print(f"Unexpected error: {str(e)}")
raise
def _generate_agent_configurations(
self,
analysis: Dict[str, Any],
project_config: Dict[str, Any]
) -> List[AgentConfig]:
"""Generate optimized agent configurations based on project analysis"""
configs = []
# Nexus configuration for code optimization
nexus_config = AgentConfig(
name="nexus",
optimization_level="enterprise" if project_config.get('team_size', 0) > 10 else "standard",
languages=analysis.get('detected_languages', []),
architecture_patterns=analysis.get('architecture_patterns', []),
learning_rate="adaptive",
performance_monitoring=True
)
configs.append(nexus_config)
# Sentinel configuration for comprehensive testing
sentinel_config = AgentConfig(
name="sentinel",
coverage_threshold=project_config.get('coverage_target', 85),
test_types=["unit", "integration", "e2e", "performance"],
edge_case_detection=True,
security_testing=project_config.get('security_required', True)
)
configs.append(sentinel_config)
# Conditional agent deployment based on project needs
if analysis.get('infrastructure_complexity', 'low') != 'low':
oracle_config = AgentConfig(
name="oracle",
cloud_providers=project_config.get('cloud_providers', ['aws']),
cost_optimization=True,
predictive_scaling=True,
disaster_recovery=project_config.get('dr_required', False)
)
configs.append(oracle_config)
if project_config.get('security_requirements', 'standard') == 'high':
aegis_config = AgentConfig(
name="aegis",
compliance_frameworks=project_config.get('compliance', []),
threat_detection_sensitivity="high",
auto_remediation=True
)
configs.append(aegis_config)
return configs
async def _create_automated_workflows(
self,
project_config: Dict[str, Any],
deployment: Dict[str, Any]
) -> List[Dict[str, Any]]:
"""Create automated workflows for development processes"""
workflows = []
# Code review automation workflow
code_review_workflow = WorkflowConfig(
name="automated-code-review",
trigger={
"type": "pull_request",
"branches": ["main", "develop"],
"conditions": ["files_changed"]
},
steps=[
{
"agent": "nexus",
"action": "analyze_code_changes",
"config": {"include_suggestions": True}
},
{
"agent": "sentinel",
"action": "run_affected_tests",
"config": {"parallel": True}
},
{
"agent": "aegis",
"action": "security_scan",
"config": {"fail_on_high_severity": True}
},
{
"agent": "herald",
"action": "notify_reviewers",
"config": {"include_summary": True}
}
],
failure_handling="notify_and_block"
)
workflow_result = await self.client.workflows.create(code_review_workflow)
workflows.append(workflow_result)
# Deployment pipeline workflow
deployment_workflow = WorkflowConfig(
name="automated-deployment",
trigger={
"type": "merge_to_main",
"conditions": ["tests_passed", "review_approved"]
},
steps=[
{
"agent": "weaver",
"action": "prepare_deployment",
"config": {"environment": "staging"}
},
{
"agent": "sentinel",
"action": "run_integration_tests",
"config": {"environment": "staging"}
},
{
"agent": "oracle",
"action": "provision_resources",
"config": {"auto_scale": True}
},
{
"agent": "weaver",
"action": "deploy_application",
"config": {"strategy": "blue_green"}
},
{
"agent": "aegis",
"action": "security_verification",
"config": {"environment": "production"}
}
],
rollback_on_failure=True
)
deployment_result = await self.client.workflows.create(deployment_workflow)
workflows.append(deployment_result)
return workflows
async def monitor_project_health(self) -> Dict[str, Any]:
"""Monitor overall project health and performance"""
# Get metrics from all agents
agent_metrics = await self.client.metrics.get_agent_metrics(
timeframe="24h",
include_predictions=True
)
# Get workflow execution status
workflow_status = await self.client.workflows.get_execution_status(
timeframe="7d"
)
# Get cost analysis
cost_analysis = await self.client.analytics.get_cost_analysis(
include_projections=True,
breakdown_by_agent=True
)
# Generate health score
health_score = await self.client.analytics.calculate_health_score(
metrics=agent_metrics,
workflows=workflow_status,
costs=cost_analysis
)
return {
'health_score': health_score,
'agent_performance': agent_metrics,
'workflow_efficiency': workflow_status,
'cost_optimization': cost_analysis,
'recommendations': await self._generate_optimization_recommendations()
}
async def _generate_optimization_recommendations(self) -> List[Dict[str, Any]]:
"""Generate optimization recommendations based on current performance"""
recommendations = await self.client.analytics.get_recommendations(
categories=['performance', 'cost', 'security', 'productivity'],
priority_threshold='medium'
)
return recommendations
# Usage example
async def main():
workflow_manager = DevelopmentWorkflowManager(
api_key="your_arkos_api_key",
environment="production"
)
project_config = {
'path': '/path/to/project',
'technologies': ['python', 'react', 'postgresql'],
'team_size': 12,
'security_requirements': 'high',
'compliance': ['soc2', 'gdpr'],
'cloud_providers': ['aws', 'azure']
}
# Setup automation
setup_result = await workflow_manager.setup_project_automation(project_config)
print(f"Automation setup complete: {setup_result}")
# Monitor health
health_status = await workflow_manager.monitor_project_health()
print(f"Project health score: {health_status['health_score']}")
if __name__ == "__main__":
asyncio.run(main())