The Teams Service enables you to create and manage multi-agent teams that can collaborate on complex tasks. Teams consist of multiple agents working together under a team leader’s coordination.
from kubiya import ControlPlaneClientclient = ControlPlaneClient()# List all teamsteams = client.teams.list()# Get a specific teamteam = client.teams.get(team_id="team-uuid")# Create a new teamteam_data = { "name": "DevOps Team", "description": "Team for infrastructure automation", "runtime": "default"}created_team = client.teams.create(team_data)
Retrieve all teams in your organization with optional filtering:
Copy
Ask AI
# List all teamsteams = client.teams.list()# List with paginationteams = client.teams.list(skip=0, limit=50)# Filter by statusactive_teams = client.teams.list(status_filter="active")inactive_teams = client.teams.list(status_filter="inactive")
Parameters:
skip (int, optional): Number of records to skip for pagination (default: 0)
limit (int, optional): Maximum number of teams to return (default: 100)
status_filter (str, optional): Filter by status: ‘active’, ‘inactive’, ‘archived’, or ‘idle’
Returns: List of team dictionaries with agent information
Execute a team task with real-time streaming responses:
Copy
Ask AI
execution_data = { "prompt": "Analyze the production database performance", "stream": True, "worker_queue_id": "queue-uuid"}# Stream the execution resultsfor chunk in client.teams.execute_stream( team_id="team-uuid", execution_data=execution_data): # Process each chunk as it arrives print(chunk.decode('utf-8'), end='', flush=True)
Here’s a complete example of creating and using a team:
Copy
Ask AI
from kubiya import ControlPlaneClientclient = ControlPlaneClient()# 1. Create a new teamteam_data = { "name": "DevOps Automation Team", "description": "Handles infrastructure and deployment tasks", "runtime": "default", "configuration": { "max_concurrent_tasks": 3 }}team = client.teams.create(team_data)print(f"Created team: {team['id']}")# 2. Add agents to the teamagent_ids = ["agent-1-uuid", "agent-2-uuid", "agent-3-uuid"]for agent_id in agent_ids: result = client.teams.add_agent( team_id=team['id'], agent_id=agent_id ) print(f"Added agent {agent_id}")# 3. Execute a task with the teamexecution_data = { "prompt": "Check the health of all production services", "worker_queue_id": "production-queue-uuid", "system_prompt": "Coordinate with team members to check all services"}print("\nExecuting team task...")for chunk in client.teams.execute_stream( team_id=team['id'], execution_data=execution_data): print(chunk.decode('utf-8'), end='', flush=True)# 4. Get updated team infoupdated_team = client.teams.get(team_id=team['id'])print(f"\n\nTeam has {len(updated_team.get('agents', []))} agents")
from kubiya.resources.exceptions import TeamErrortry: team = client.teams.get(team_id="invalid-id")except TeamError as e: print(f"Team error: {e}")except Exception as e: print(f"Unexpected error: {e}")