Files
aitbc/packages/py/aitbc-agent-sdk/src/aitbc_agent/compute_consumer.py
aitbc1 8b8d639bf7
All checks were successful
API Endpoint Tests / test-api-endpoints (push) Successful in 39s
Integration Tests / test-service-integration (push) Successful in 44s
Package Tests / test-python-packages (map[name:aitbc-core path:packages/py/aitbc-core]) (push) Successful in 16s
Package Tests / test-python-packages (map[name:aitbc-agent-sdk path:packages/py/aitbc-agent-sdk]) (push) Successful in 30s
Package Tests / test-python-packages (map[name:aitbc-crypto path:packages/py/aitbc-crypto]) (push) Successful in 20s
Package Tests / test-python-packages (map[name:aitbc-sdk path:packages/py/aitbc-sdk]) (push) Successful in 20s
Package Tests / test-javascript-packages (map[name:aitbc-sdk-js path:packages/js/aitbc-sdk]) (push) Successful in 17s
Package Tests / test-javascript-packages (map[name:aitbc-token path:packages/solidity/aitbc-token]) (push) Successful in 1m17s
Python Tests / test-python (push) Successful in 1m7s
Smart Contract Tests / test-solidity (map[name:aitbc-token path:packages/solidity/aitbc-token]) (push) Successful in 30s
Security Scanning / security-scan (push) Successful in 1m5s
Smart Contract Tests / test-solidity (map[name:zk-circuits path:apps/zk-circuits]) (push) Successful in 49s
Smart Contract Tests / lint-solidity (push) Successful in 54s
fix: resolve CI failures across all workflows
aitbc-agent-sdk (package-tests.yml):
- Add AITBCAgent convenience class matching test expectations
- Fix test_agent_sdk.py: was importing nonexistent AITBCAgent, now tests
  the real API (Agent.create, AgentCapabilities, to_dict) plus AITBCAgent
- Fix 3 remaining mypy errors: supported_models Optional coercion (line 64),
  missing return types on _submit_to_marketplace/_update_marketplace_offer
- Run black on all 5 src files — zero mypy errors, zero black warnings
- All 6 tests pass

python-tests.yml:
- Add pynacl to pip install (aitbc-crypto and aitbc-sdk import nacl)
- Add pynacl>=1.5.0 to root requirements.txt

Service readiness (api-endpoint-tests.yml, integration-tests.yml):
- Replace curl -sf with curl http_code check — -sf fails on 404 responses
  but port 8006 (blockchain RPC) returns 404 on / while being healthy
- Blockchain RPC uses REST /rpc/* endpoints, not JSON-RPC POST to /
  Fix test_api_endpoints.py to test /health, /rpc/head, /rpc/info, /rpc/supply
- Remove dead test_rpc() function, add blockchain RPC to perf tests
- All 4 services now pass: coordinator, exchange, wallet, blockchain_rpc
- Integration-tests: check is-active before systemctl start to avoid
  spurious warnings for already-running services

Hardhat compile (smart-contract-tests.yml, package-tests.yml):
- Relax engines field from >=24.14.0 to >=18.0.0 (CI has v24.13.0)
- Remove 2>/dev/null from hardhat compile/test so errors are visible
- Remove 2>/dev/null from npm run build/test in package-tests JS section
2026-03-29 13:20:58 +02:00

89 lines
2.6 KiB
Python

"""
Compute Consumer Agent - for agents that consume computational resources
"""
import asyncio
import logging
from typing import Dict, List, Optional, Any
from datetime import datetime
from dataclasses import dataclass
from .agent import Agent, AgentCapabilities
logger = logging.getLogger(__name__)
@dataclass
class JobRequest:
"""Compute job request specification"""
consumer_id: str
job_type: str
model_id: Optional[str] = None
input_data: Optional[Dict[str, Any]] = None
requirements: Optional[Dict[str, Any]] = None
max_price_per_hour: float = 0.0
priority: str = "normal"
deadline: Optional[str] = None
@dataclass
class JobResult:
"""Result from a compute job"""
job_id: str
provider_id: str
status: str # "completed", "failed", "timeout"
output: Optional[Dict[str, Any]] = None
execution_time: float = 0.0
cost: float = 0.0
quality_score: Optional[float] = None
class ComputeConsumer(Agent):
"""Agent that consumes computational resources from the network"""
def __init__(self, *args: Any, **kwargs: Any) -> None:
super().__init__(*args, **kwargs)
self.pending_jobs: List[JobRequest] = []
self.completed_jobs: List[JobResult] = []
self.total_spent: float = 0.0
async def submit_job(
self,
job_type: str,
input_data: Dict[str, Any],
requirements: Optional[Dict[str, Any]] = None,
max_price: float = 0.0,
) -> str:
"""Submit a compute job to the network"""
job = JobRequest(
consumer_id=self.identity.id,
job_type=job_type,
input_data=input_data,
requirements=requirements or {},
max_price_per_hour=max_price,
)
self.pending_jobs.append(job)
logger.info(f"Job submitted: {job_type} by {self.identity.id}")
# TODO: Submit to coordinator for matching
await asyncio.sleep(0.1)
return f"job_{self.identity.id}_{len(self.pending_jobs)}"
async def get_job_status(self, job_id: str) -> Dict[str, Any]:
"""Check status of a submitted job"""
# TODO: Query coordinator for job status
return {"job_id": job_id, "status": "pending", "progress": 0.0}
async def cancel_job(self, job_id: str) -> bool:
"""Cancel a pending job"""
logger.info(f"Job cancelled: {job_id}")
return True
def get_spending_summary(self) -> Dict[str, Any]:
"""Get spending summary"""
return {
"total_spent": self.total_spent,
"completed_jobs": len(self.completed_jobs),
"pending_jobs": len(self.pending_jobs),
}