Skip to main content
The Agents Service provides comprehensive management of AI agents through the Kubiya platform, including lifecycle management, access control, environment configuration, and tool integration.

Quick Start

from kubiya import KubiyaClient

client = KubiyaClient(api_key="your-api-key")

# Create an agent
agent = client.agents.create(
    name="devops-assistant",
    description="AI assistant for DevOps automation",
    llm_model="claude-sonnet-4",
    tools=["kubectl", "terraform"],
    integrations=["slack", "github"]
)

print(f"Created agent: {agent['name']} (UUID: {agent['uuid']})")

Core Operations

Create Agent

agent = client.agents.create(
    name="my-assistant",
    description="A helpful AI assistant",
    llm_model="claude-sonnet-4",
    ai_instructions="You are a helpful assistant. Always be clear and concise.",
    tools=["kubectl", "docker"],
    integrations=["slack"],
    environment={"LOG_LEVEL": "INFO", "REGION": "us-east-1"}
)

List Agents

# List all agents
agents = client.agents.list(limit=10)

# With filtering
agents = client.agents.list(
    filter_term="devops",
    sort_by="created",
    limit=20
)

for agent in agents:
    print(f"{agent['name']}: {agent.get('description', 'No description')}")

Get Agent Details

agent = client.agents.get("agent-uuid-here")
print(f"Agent: {agent['name']}")
print(f"Model: {agent['llm_model']}")
print(f"Tools: {agent.get('tools', [])}")

Update Agent

client.agents.edit(
    "agent-uuid",
    llm_model="claude-opus-4",
    add_tools=["new-tool"],
    remove_tools=["old-tool"]
)

Delete Agent

client.agents.delete("agent-uuid")

Access Control

Manage who can interact with your agents:

View Access Settings

access_info = client.agents.access.show("agent-uuid")
print(f"Allowed users: {access_info.get('users', [])}")
print(f"Allowed groups: {access_info.get('groups', [])}")

Add Users

client.agents.access.add_user(
    "agent-uuid",
    ["user1@company.com", "user2@company.com"]
)

Add Groups

client.agents.access.add_group(
    "agent-uuid",
    ["devops-team", "engineering"]
)

Remove Access

# Remove specific users
client.agents.access.remove_user("agent-uuid", ["user@company.com"])

# Clear all access restrictions (open access)
client.agents.access.clear("agent-uuid")

Environment Variables

Configure agent environment:

List Environment Variables

env_vars = client.agents.env.list("agent-uuid")
for key, value in env_vars.items():
    print(f"{key}={value}")

Set Environment Variables

client.agents.env.set("agent-uuid", {
    "API_ENDPOINT": "https://api.example.com",
    "TIMEOUT": "30",
    "DEBUG": "true"
})

Remove Environment Variables

client.agents.env.unset("agent-uuid", ["DEBUG", "OLD_VAR"])

AI Instructions (Prompts)

Configure agent behavior with custom instructions:

Set Instructions

instructions = """
You are a DevOps assistant specialized in Kubernetes and cloud infrastructure.

Guidelines:
- Always verify kubectl context before making changes
- Explain what each command does before executing
- Ask for confirmation for destructive operations
- Provide clear, step-by-step instructions
"""

client.agents.prompt.set("agent-uuid", instructions)

Get Current Instructions

current_prompt = client.agents.prompt.get("agent-uuid")
print(current_prompt)

Tool Management

Manage agent capabilities:

Add Tools

client.agents.tools.add("agent-uuid", ["docker", "helm", "terraform"])

Remove Tools

client.agents.tools.remove("agent-uuid", ["old-tool"])

List Available Tools

tools = client.agents.tools.list_available()
for tool in tools:
    print(f"{tool['name']}: {tool['description']}")

Error Handling

from kubiya.kubiya_services.exceptions import AgentError

try:
    agent = client.agents.create(name="my-agent")
except AgentError as e:
    print(f"Failed to create agent: {e}")
    # Handle error appropriately

Complete Example

from kubiya import KubiyaClient
from kubiya.kubiya_services.exceptions import AgentError

client = KubiyaClient()

try:
    # Create agent
    agent = client.agents.create(
        name="kubernetes-helper",
        description="Kubernetes management assistant",
        llm_model="claude-sonnet-4",
        ai_instructions="""
        You are a Kubernetes expert assistant.
        Always verify the cluster context before operations.
        Explain commands clearly.
        """,
        tools=["kubectl", "helm"],
        integrations=["slack"]
    )

    agent_uuid = agent['uuid']
    print(f"✅ Created agent: {agent['name']}")

    # Configure access
    client.agents.access.add_group(agent_uuid, ["devops-team"])
    print("✅ Added devops-team access")

    # Set environment
    client.agents.env.set(agent_uuid, {
        "CLUSTER": "production",
        "REGION": "us-east-1"
    })
    print("✅ Configured environment")

    # Verify
    agent_details = client.agents.get(agent_uuid)
    print(f"✅ Agent ready: {agent_details['name']}")

except AgentError as e:
    print(f"❌ Error: {e}")

Best Practices

# Good
agent = client.agents.create(name="production-k8s-assistant")

# Avoid
agent = client.agents.create(name="agent1")
Provide detailed instructions for consistent behavior:
instructions = """
Role: DevOps automation assistant
Responsibilities: Kubernetes management, deployment automation
Guidelines: Always verify context, explain actions, ask for confirmations
"""
client.agents.prompt.set(agent_uuid, instructions)
Restrict agent access to appropriate teams:
client.agents.access.add_group(agent_uuid, ["devops-team"])
# Don't leave agents with open access in production
Configure agents with environment variables instead of hardcoding:
client.agents.env.set(agent_uuid, {
    "CLUSTER": os.getenv("CLUSTER"),
    "REGION": os.getenv("REGION")
})

Next Steps