-
Notifications
You must be signed in to change notification settings - Fork 8
Add orchestrator pattern example (06-task-dependencies) #403
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| # 06 — Task Dependencies (Orchestrator Pattern) | ||
|
|
||
| Chain multiple Tasks together so one agent's output feeds into the next. | ||
| This pattern lets you break complex work into specialized steps — for | ||
| example, one agent writes code and another reviews it. | ||
|
|
||
| ## Use Case | ||
|
|
||
| Run a multi-step workflow where a coding agent creates a PR, then a | ||
| review agent examines the PR and leaves feedback. The review agent | ||
| automatically receives the branch name and PR URL produced by the first | ||
| agent through prompt templates. | ||
|
|
||
| ## How It Works | ||
|
|
||
| Axon's `dependsOn` field keeps Task B in a `Waiting` phase until Task A | ||
| succeeds. When Task A completes, Axon captures its structured outputs | ||
| (lines matching `key: value` printed between output markers) and makes | ||
| them available to Task B via Go template syntax in the prompt: | ||
|
|
||
| ``` | ||
| {{ index .Deps "<task-name>" "Results" "<key>" }} | ||
| ``` | ||
|
|
||
| The controller resolves the template before creating Task B's Job, so the | ||
| downstream agent sees a fully rendered prompt with concrete values. | ||
|
|
||
| ## Resources | ||
|
|
||
| | File | Kind | Purpose | | ||
| |------|------|---------| | ||
| | `github-token-secret.yaml` | Secret | GitHub token for cloning and PR creation | | ||
| | `credentials-secret.yaml` | Secret | Claude OAuth token for the agents | | ||
| | `workspace.yaml` | Workspace | Git repository to clone | | ||
| | `task-a-implement.yaml` | Task | Step 1: implement a feature and open a PR | | ||
| | `task-b-review.yaml` | Task | Step 2: review the PR (depends on Task A) | | ||
|
|
||
| ## Steps | ||
|
|
||
| 1. **Edit the secrets** — replace placeholders in both `github-token-secret.yaml` | ||
| and `credentials-secret.yaml` with your real tokens. | ||
|
|
||
| 2. **Edit `workspace.yaml`** — set your repository URL and branch. | ||
|
|
||
| 3. **Apply all resources at once:** | ||
|
|
||
| ```bash | ||
| kubectl apply -f examples/06-task-dependencies/ | ||
| ``` | ||
|
|
||
| 4. **Watch the Tasks:** | ||
|
|
||
| ```bash | ||
| kubectl get tasks -w | ||
| ``` | ||
|
|
||
| You should see Task A start immediately while Task B stays in `Waiting`. | ||
| Once Task A succeeds, Task B transitions to `Pending` and then `Running`. | ||
|
|
||
| 5. **Stream logs for each task:** | ||
|
|
||
| ```bash | ||
| # In one terminal: | ||
| axon logs implement-feature -f | ||
|
|
||
| # In another terminal (once Task B starts): | ||
| axon logs review-feature -f | ||
| ``` | ||
|
|
||
| 6. **Cleanup:** | ||
|
|
||
| ```bash | ||
| kubectl delete -f examples/06-task-dependencies/ | ||
| ``` | ||
|
|
||
| ## Key Behaviors | ||
|
|
||
| - **Automatic waiting** — Task B never starts until Task A succeeds. No | ||
| polling or manual coordination needed. | ||
| - **Failure propagation** — if Task A fails, Task B immediately fails with | ||
| a message indicating the dependency failure. | ||
| - **Cycle detection** — the controller detects circular dependencies at | ||
| creation time and fails the task immediately. | ||
| - **Branch locking** — both tasks use the same branch. The controller | ||
| ensures only one runs at a time (Task B waits for the lock too). | ||
| - **Output forwarding** — Task A's captured outputs (branch, PR URL) are | ||
| injected into Task B's prompt via Go templates. | ||
|
|
||
| ## Extending This Pattern | ||
|
|
||
| You can chain more than two tasks by adding additional `dependsOn` | ||
| references. For example, a three-step pipeline: | ||
|
|
||
| ```yaml | ||
| # task-c-merge.yaml | ||
| apiVersion: axon.io/v1alpha1 | ||
| kind: Task | ||
| metadata: | ||
| name: merge-feature | ||
| spec: | ||
| type: claude-code | ||
| prompt: | | ||
| The review for PR {{ index .Deps "review-feature" "Results" "pr" }} | ||
| has been completed. If the review approved the changes, merge the PR. | ||
| dependsOn: | ||
| - review-feature | ||
| credentials: | ||
| type: oauth | ||
| secretRef: | ||
| name: claude-oauth-token | ||
| workspaceRef: | ||
| name: my-workspace | ||
| ``` | ||
|
|
||
| A task can also depend on multiple upstream tasks: | ||
|
|
||
| ```yaml | ||
| dependsOn: | ||
| - implement-backend | ||
| - implement-frontend | ||
| ``` | ||
|
|
||
| In this case, the task waits until **all** listed dependencies succeed. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| apiVersion: v1 | ||
| kind: Secret | ||
| metadata: | ||
| name: claude-oauth-token | ||
| type: Opaque | ||
| stringData: | ||
| # TODO: Replace with your Claude OAuth token | ||
| CLAUDE_CODE_OAUTH_TOKEN: "REPLACE-ME" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| apiVersion: v1 | ||
| kind: Secret | ||
| metadata: | ||
| name: github-token | ||
| type: Opaque | ||
| stringData: | ||
| # TODO: Replace with your GitHub Personal Access Token | ||
| # Required permissions: repo (for private repos), workflow (optional) | ||
| GITHUB_TOKEN: "ghp_REPLACE-ME" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| apiVersion: axon.io/v1alpha1 | ||
| kind: Task | ||
| metadata: | ||
| name: implement-feature | ||
| spec: | ||
| type: claude-code | ||
| # TODO: Replace with a prompt describing the feature to implement | ||
| prompt: | | ||
| Implement a /health endpoint that returns JSON {"status": "ok"}. | ||
| Create a branch, commit the changes, and open a PR. | ||
| credentials: | ||
| type: oauth | ||
| secretRef: | ||
| name: claude-oauth-token | ||
| workspaceRef: | ||
| name: my-workspace | ||
| branch: "orchestrator-example" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| apiVersion: axon.io/v1alpha1 | ||
| kind: Task | ||
| metadata: | ||
| name: review-feature | ||
| spec: | ||
| type: claude-code | ||
| # This prompt uses Go template syntax to reference outputs from Task A. | ||
| # {{ index .Deps "<name>" "Results" "<key>" }} accesses structured outputs. | ||
| # {{ index .Deps "<name>" "Outputs" }} accesses the raw output list. | ||
| prompt: | | ||
| Review the PR at {{ index .Deps "implement-feature" "Results" "pr" }} | ||
| on branch {{ index .Deps "implement-feature" "Results" "branch" }}. | ||
|
|
||
| Check for: | ||
| - Correctness and edge cases | ||
| - Test coverage | ||
| - Code style and documentation | ||
|
|
||
| Leave a review on the PR with your findings. | ||
| dependsOn: | ||
| - implement-feature | ||
| credentials: | ||
| type: oauth | ||
| secretRef: | ||
| name: claude-oauth-token | ||
| workspaceRef: | ||
| name: my-workspace | ||
| branch: "orchestrator-example" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| apiVersion: axon.io/v1alpha1 | ||
| kind: Workspace | ||
| metadata: | ||
| name: my-workspace | ||
| spec: | ||
| # TODO: Replace with your repository URL | ||
| repo: https://github.com/your-org/your-repo.git | ||
| ref: main | ||
| secretRef: | ||
| name: github-token |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: Template references wrong dependency output.
review-featureis a code-review task and doesn't produce aproutput — the PR URL comes fromimplement-feature. Either addimplement-featuretodependsOnand reference it directly, or reference a key thatreview-featurewould actually produce.Prompt for AI agents