The Agents Service provides programmatic access to create, configure, and manage AI agents in the Kubiya platform. Agents are autonomous AI assistants that can perform tasks, execute workflows, and interact with various tools and integrations.
For conceptual information about agents and how they work, see Agents Core Concepts.
Use the Agents Service when you want to manage your agent catalog from code: listing and auditing existing agents, rolling out new versions with updated models or skills, enforcing consistent configurations across environments, and triggering executions from CI/CD, runbooks, or internal tools.
# List agents with paginationskip = 0limit = 20while True: agents = client.agents.list(skip=skip, limit=limit) if not agents: break for agent in agents: print(f"Agent: {agent['name']}") skip += limit
# List only active agentsactive_agents = client.agents.list(status_filter="active")print(f"Active agents: {len(active_agents)}")for agent in active_agents: print(f" - {agent['name']}")# List inactive agentsinactive_agents = client.agents.list(status_filter="inactive")print(f"Inactive agents: {len(inactive_agents)}")
def toggle_agent_status(agent_id: str, status: str): """Enable or disable an agent""" if status not in ["active", "inactive"]: raise ValueError("Status must be 'active' or 'inactive'") update_data = {"status": status} updated_agent = client.agents.update(agent_id, update_data) print(f"Agent status set to: {status}") return updated_agent# Usagetoggle_agent_status("agent-uuid", "inactive") # Disabletoggle_agent_status("agent-uuid", "active") # Enable
# Execute an agentexecution_data = { "prompt": "Check the health of all production services"}execution = client.agents.execute( agent_id="agent-uuid", execution_data=execution_data)print(f"Execution started: {execution['execution_id']}")print(f"Status: {execution.get('status')}")
The following examples show how to use the Agents Service for common real-world scenarios, such as creating, updating, and executing agents. Each example includes a short explanation of when and why you might use it.
Use this pattern to generate a high-level inventory of all agents in your organization so you can understand coverage by runtime, model, skills, and integrations.
def generate_agent_inventory(): """Generate comprehensive agent inventory""" all_agents = [] skip = 0 limit = 100 while True: agents = client.agents.list(skip=skip, limit=limit) if not agents: break all_agents.extend(agents) skip += limit inventory = { "total_agents": len(all_agents), "by_runtime": {}, "by_status": {}, "by_model": {}, "skills_usage": {}, "integration_usage": {} } for agent in all_agents: # Count by runtime runtime = agent.get('runtime', 'unknown') inventory['by_runtime'][runtime] = inventory['by_runtime'].get(runtime, 0) + 1 # Count by status status = agent.get('status', 'active') inventory['by_status'][status] = inventory['by_status'].get(status, 0) + 1 # Count by model model = agent.get('model', 'unknown') inventory['by_model'][model] = inventory['by_model'].get(model, 0) + 1 # Track skill usage for skill in agent.get('skills', []): inventory['skills_usage'][skill] = inventory['skills_usage'].get(skill, 0) + 1 # Track integration usage for integration in agent.get('integrations', []): inventory['integration_usage'][integration] = inventory['integration_usage'].get(integration, 0) + 1 return inventory# Usageinventory = generate_agent_inventory()print(f"Agent Inventory Report:")print(f" Total Agents: {inventory['total_agents']}")print(f"\nBy Runtime:")for runtime, count in inventory['by_runtime'].items(): print(f" {runtime}: {count}")print(f"\nTop 5 Skills:")top_skills = sorted(inventory['skills_usage'].items(), key=lambda x: x[1], reverse=True)[:5]for skill, count in top_skills: print(f" {skill}: {count} agents")
Use this validator before creating or updating agents to catch missing fields or questionable configurations early, instead of discovering issues at execution time.
def validate_agent_config(agent_config: dict): """Validate agent configuration before creation""" errors = [] warnings = [] # Required fields if not agent_config.get('name'): errors.append("Agent name is required") if not agent_config.get('runtime'): errors.append("Runtime is required") if not agent_config.get('model'): errors.append("Model is required") # Validate runtime valid_runtimes = ["agno", "claude_code"] if agent_config.get('runtime') not in valid_runtimes: errors.append(f"Runtime must be one of: {valid_runtimes}") # Validate skills if not agent_config.get('skills'): warnings.append("No skills specified - agent may have limited capabilities") # Validate integrations if not agent_config.get('integrations'): warnings.append("No integrations specified") return { "valid": len(errors) == 0, "errors": errors, "warnings": warnings }# Usageagent_config = { "name": "my-agent", "runtime": "agno", "model": "kubiya/claude-sonnet-4"}validation = validate_agent_config(agent_config)if validation['valid']: print("✅ Configuration is valid") if validation['warnings']: print("⚠️ Warnings:") for warning in validation['warnings']: print(f" - {warning}") # Create agent agent = client.agents.create(agent_config)else: print("❌ Configuration is invalid:") for error in validation['errors']: print(f" - {error}")
Use cloning when you want to spin up a new agent that is similar to an existing one (for a new team, environment, or experiment) while safely applying only a small set of changes.
Agent operations can fail if an agent does not exist, has an invalid configuration, or if there are connectivity or permission issues when executing workflows. The following examples show how to catch AgentError, surface useful information, and fall back to safer behavior like listing available agents.
from kubiya.resources.exceptions import AgentErrortry: # Try to get an agent agent = client.agents.get("non-existent-agent")except AgentError as e: print(f"Agent error: {e}") # Handle error - maybe list all agents print("Available agents:") agents = client.agents.list(limit=10) for agent in agents: print(f" - {agent['name']}")# Execute with error handlingtry: execution = client.agents.execute( agent_id="agent-uuid", execution_data={"prompt": "Deploy app"} ) print(f"Execution started: {execution['execution_id']}")except AgentError as e: print(f"Execution failed: {e}")
Choose runtimes and models that match the kind of work the agent will perform, balancing capability and cost for code-heavy versus general-purpose scenarios.
# For code-heavy taskscode_agent = { "name": "code-assistant", "runtime": "claude_code", "model": "kubiya/claude-opus-4", # Best for code "skills": ["github", "code-analysis"]}# For general tasksgeneral_agent = { "name": "general-assistant", "runtime": "agno", "model": "kubiya/claude-sonnet-4", # Cost-effective "skills": ["knowledge-base", "ticketing"]}
Treat agents as long-lived resources with a lifecycle: pause when not in use, resume when needed, and retire carefully after archiving any important state or configuration.