Skip to main content

Create a Multi-Agent Pipeline with kubeswarm

Compose multiple kubeswarm agents into a DAG pipeline using SwarmTeam. Each step targets an agent, passes data via template expressions and tracks execution in a SwarmRun record.

Define agents

apiVersion: kubeswarm.io/v1alpha1
kind: SwarmAgent
metadata:
name: researcher
spec:
model: gpt-4o-mini
prompt:
inline: "You are a research assistant."
apiKeyRef:
name: provider-api-keys
key: OPENAI_API_KEY
---
apiVersion: kubeswarm.io/v1alpha1
kind: SwarmAgent
metadata:
name: writer
spec:
model: claude-sonnet-4-6
prompt:
inline: "You are a technical writer."
apiKeyRef:
name: provider-api-keys
key: ANTHROPIC_API_KEY

Define the team

apiVersion: kubeswarm.io/v1alpha1
kind: SwarmTeam
metadata:
name: blog-pipeline
spec:
roles:
- name: researcher
swarmAgent: researcher
- name: writer
swarmAgent: writer

inputs:
- name: topic
type: string
required: true

pipeline:
- role: researcher
inputs:
prompt: "Research this topic: {{ .input.topic }}"
- role: writer
dependsOn: [researcher]
inputs:
prompt: |
Write a blog post based on this research:
{{ .steps.researcher.output }}

output: "{{ .steps.writer.output }}"
timeoutSeconds: 600

Trigger a run

kubectl apply -f - <<EOF
apiVersion: kubeswarm.io/v1alpha1
kind: SwarmRun
metadata:
name: blog-run-1
spec:
teamRef: blog-pipeline
input:
topic: "Kubernetes-native agent orchestration"
EOF

kubectl get swrun blog-run-1 -w

Template syntax

ExpressionDescription
{{ .input.<key> }}Pipeline input value
{{ .steps.<role>.output }}Previous step's output
{{ .steps.<role>.artifacts.<name> }}Step artifact reference