Compare commits
125 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2b2a3fda12 | |||
| 5390d4a38a | |||
| 5bc2e8d9fc | |||
| e39b173a4c | |||
| 730137cee9 | |||
| e610787c3b | |||
| 3bb388d57e | |||
| 8d0143f42a | |||
| e5411c7b3a | |||
| 3a6d4275aa | |||
| 7b51be5ba8 | |||
| 29d8544ce5 | |||
| c7d510349e | |||
| 81f81460aa | |||
| ba7db2f315 | |||
| ed3e0e5a06 | |||
| bd433239d7 | |||
| 7b782589d3 | |||
| 06a4375e47 | |||
| 1b371470a9 | |||
| 86ef6232bb | |||
| 10a5a5b235 | |||
| 28c411f0f7 | |||
| 99a956dec3 | |||
| 84cb4532f5 | |||
| 3d0ea0666e | |||
| cddf85c218 | |||
| c4eec47cbc | |||
| 87f011471b | |||
| 8ed0c21aa3 | |||
| 93ecf886a5 | |||
| 0120d6eb49 | |||
| decc7ebe1d | |||
| fc4921087f | |||
| 98cbafd11a | |||
| bba3b8ba98 | |||
| 460f1ef45a | |||
| 2cf95b27c8 | |||
| 700b72b0d6 | |||
| 4c6d8ec80b | |||
| 96fc06b9e4 | |||
| 167ca22107 | |||
| 6681a0971a | |||
| 1d795ef975 | |||
| 4faafdf3e9 | |||
| 56df17ce25 | |||
| e82d44e94a | |||
| 7a70fcf114 | |||
| 3d35b77c23 | |||
| ec698505ec | |||
| b940dd4233 | |||
| 39e92203dc | |||
| 3fc2364eea | |||
| 801f8f0f83 | |||
| a565dce4a0 | |||
| 4806f2fa17 | |||
| a0bc2287ff | |||
| b751497385 | |||
| ad500d58c8 | |||
| cae5549c73 | |||
| 850b202964 | |||
| 892fc847f0 | |||
| 7f78bbf814 | |||
| fc6e24daa3 | |||
| 7e0b6fd3fa | |||
| 1091e68bc1 | |||
| 7d2586a2f9 | |||
| 2bd02cc960 | |||
| 9dccdb4f69 | |||
| d1a34efadc | |||
| 8c7284ab80 | |||
| 5274f7c44f | |||
| c77f19ec80 | |||
| cd576e780c | |||
| 86d66b446f | |||
| 4150e8dc89 | |||
| 60612dc664 | |||
| ed43db5276 | |||
| 9d6d2d6c91 | |||
| 776fe1a36a | |||
| 84c1ee7471 | |||
| 1a9e94219a | |||
| c7df280d93 | |||
| 3b367975a3 | |||
| 0d4a101532 | |||
| ad8ff2abde | |||
| 5e6d51d261 | |||
| 687a33faee | |||
| 48e752bbce | |||
| b9e4bd171f | |||
| d551996a46 | |||
| 80d2d7306f | |||
| 31e146e61d | |||
| 0e3a749556 | |||
| c9f238955c | |||
| c264589a1f | |||
| 6836b49fa0 | |||
| da5b1a2599 | |||
| 3560208edc | |||
| 5f7f733713 | |||
| 29e49c92ea | |||
| 271af4d98e | |||
| 66acee0416 | |||
| e70111426b | |||
| 0314c8f55b | |||
| b3cc4a4ba4 | |||
| 765a842f2b | |||
| 7604cac060 | |||
| 234da38cd5 | |||
| 967e1cfd9b | |||
| 02aac71019 | |||
| 415e95c0f1 | |||
| 36c42d0cfa | |||
| 459dff8e7a | |||
| 6c74ae0f9c | |||
| 224e107f1c | |||
| e0b9f1323f | |||
| 35d3d99428 | |||
| 656c0ce9d6 | |||
| 7734f5605d | |||
| affd61e69b | |||
| 171da77817 | |||
| 83a6b2004a | |||
| ae5ead7914 | |||
| a1d17ec984 |
@@ -21,9 +21,9 @@ changes, architectural rewrites. Those go to the human.
|
||||
|
||||
## Work queue (ranked)
|
||||
|
||||
1. **Fix AtlasCloud A2A streaming fallback tool-call reporting** ([#4297](https://github.com/micro/go-micro/issues/4297)) — The guarded-delegation failure closed with #4307, so the top remaining Now-phase provider defect is the A2A streaming fallback path reporting neither tool-call evidence nor run metadata (`tool=false runInfo=false`). A2A streaming is a critical interop seam for agents-as-services, and the fix should stay narrowly focused on surfacing tool/run evidence in the existing harness.
|
||||
2. **Propagate cancellation and retry signals through provider model calls** ([#4273](https://github.com/micro/go-micro/issues/4273)) — Once the current live AtlasCloud reporting failure is stable, the remaining Now-phase resilience seam is provider-boundary cancellation/deadline/retry behavior across the agent loop. Keep it focused on fakes/tests and avoid public API or architecture changes.
|
||||
3. **CI-verify zero-to-hero deploy dry-run path** ([#4309](https://github.com/micro/go-micro/issues/4309)) — Developer adoption remains the current goal, and the docs now have a strong no-secret first-agent path; the next adoption gap is making sure the documented scaffold → run → chat → inspect → deploy dry-run lifecycle is continuously verified through the deploy boundary, not just described. This keeps the 0→hero contract honest without displacing the two active Now-phase provider/resilience fixes.
|
||||
1. **Add CI-verified first-agent chat/inspect fixture** ([#4644](https://github.com/micro/go-micro/issues/4644)) — With plan/delegate persistence hardened and the first-agent breadcrumbs refreshed, the highest-value remaining adoption gap is proving the real CLI-shaped scaffold → run → chat → inspect loop for the smallest provider-free agent. Keep this focused and separate from the richer support 0→hero reference so a new developer can trust the first-agent path without provider keys.
|
||||
2. **Add scheduled cross-provider agent conformance** ([#4649](https://github.com/micro/go-micro/issues/4649)) — The Now roadmap still calls for battle-testing the same agent scenario across providers. After the no-secret first-agent fixture, verify tool-calling, multi-step turns, plan/delegate, and guardrails on the live-provider matrix behind key-gated scheduled CI, without slowing the local harness.
|
||||
3. **Harden agent provider failure resilience** ([#4650](https://github.com/micro/go-micro/issues/4650)) — The next reliability seam is making timeouts, cancellation, rate limits, retry/backoff, and inspectable failure metadata predictable through the agent loop. Keep this scoped to existing behavior and tests; surface any breaking API or default changes as human review notes instead of queue work.
|
||||
|
||||
_Seeded by Claude Code from the roadmap + open issues; thereafter maintained by the
|
||||
architecture-review pass._
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
name: govulncheck
|
||||
|
||||
# Deterministic vulnerability gate: runs govulncheck (reachability-aware CVE
|
||||
# scanner) on every push/PR. Fails on any reachable vulnerability EXCEPT the
|
||||
# explicit ALLOWLIST of known-unfixable ones, so a new vuln breaks the build
|
||||
# while tracked, no-upstream-fix ones don't. This is the gate the loop's
|
||||
# `security` role sits on top of — the role audits; this blocks known CVEs.
|
||||
#
|
||||
# Make this a required status check on the default branch to enforce it.
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: ["**"]
|
||||
pull_request:
|
||||
branches: ["**"]
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
govulncheck:
|
||||
name: govulncheck
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: "1.25"
|
||||
check-latest: true
|
||||
- name: Install govulncheck
|
||||
run: go install golang.org/x/vuln/cmd/govulncheck@latest
|
||||
- name: Scan
|
||||
env:
|
||||
# Reachable vulnerabilities with NO upstream fix, accepted for now and
|
||||
# tracked for remediation. Remove an ID the moment its fix lands.
|
||||
# GO-2026-5004 github.com/jackc/pgx/v4 -> pgx v5 migration (#4556)
|
||||
# GO-2026-4518 github.com/jackc/pgproto3/v2 -> pgx v5 migration (#4556)
|
||||
ALLOWLIST: "GO-2026-5004 GO-2026-4518"
|
||||
run: |
|
||||
out=$(mktemp)
|
||||
govulncheck ./... >"$out" 2>&1 && code=0 || code=$?
|
||||
cat "$out"
|
||||
if [ "$code" -eq 0 ]; then
|
||||
echo "govulncheck: no reachable vulnerabilities."
|
||||
exit 0
|
||||
fi
|
||||
if [ "$code" -ne 3 ]; then
|
||||
echo "::error::govulncheck failed to run (exit $code)."
|
||||
exit 1
|
||||
fi
|
||||
found=$(grep -oE 'Vulnerability #[0-9]+: GO-[0-9]{4}-[0-9]+' "$out" | grep -oE 'GO-[0-9]{4}-[0-9]+' | sort -u)
|
||||
unexpected=""
|
||||
for id in $found; do
|
||||
case " $ALLOWLIST " in
|
||||
*" $id "*) ;;
|
||||
*) unexpected="$unexpected $id" ;;
|
||||
esac
|
||||
done
|
||||
if [ -n "$unexpected" ]; then
|
||||
echo "::error::Unexpected reachable vulnerabilities:$unexpected"
|
||||
echo "If a fix exists, bump the dependency/toolchain. If genuinely unfixable, add the ID to ALLOWLIST with a tracking issue."
|
||||
exit 1
|
||||
fi
|
||||
echo "govulncheck: only allow-listed (known-unfixable) vulnerabilities present:$found"
|
||||
echo "OK."
|
||||
@@ -21,7 +21,7 @@ jobs:
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: 1.24
|
||||
go-version: "1.25"
|
||||
check-latest: true
|
||||
cache: true
|
||||
- name: golangci-lint
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
name: "Loop: Release"
|
||||
|
||||
# Generated by `micro loop init`. Cuts the next PATCH tag
|
||||
# (vMAJOR.MINOR.PATCH+1) when the default branch has new commits
|
||||
# since the latest such tag, and pushes it with a PAT (CODEX_TRIGGER_TOKEN) so any
|
||||
# tag-triggered release workflow fires. Minor/major bumps stay with a human.
|
||||
# Generated by `micro loop init`. Cuts the next tag when the default branch has
|
||||
# new commits since the latest one, and pushes it with a PAT (CODEX_TRIGGER_TOKEN)
|
||||
# so any tag-triggered release workflow fires. The bump reflects what shipped,
|
||||
# read from the CHANGELOG [Unreleased] section: new features (Added/Changed) cut
|
||||
# a MINOR; fixes/docs only cut a PATCH; breaking changes are skipped so a MAJOR
|
||||
# stays a human decision.
|
||||
#
|
||||
# The tag MUST be pushed with a PAT, not the default GITHUB_TOKEN: a tag pushed
|
||||
# by GITHUB_TOKEN does not trigger other workflows (Actions blocks that recursion).
|
||||
@@ -66,11 +68,30 @@ jobs:
|
||||
[0-9]*.[0-9]*.[0-9]*) ;;
|
||||
*) echo "unexpected tag shape: $LATEST" ; exit 1 ;;
|
||||
esac
|
||||
NEXT="v${major}.${minor}.$((patch + 1))"
|
||||
echo "cutting: $NEXT ($COUNT commits since $LATEST)"
|
||||
|
||||
# Choose the bump from what actually shipped, read from the CHANGELOG
|
||||
# [Unreleased] section (kept current by the coherence role):
|
||||
# new features (### Added / ### Changed) -> MINOR
|
||||
# fixes/docs only -> PATCH
|
||||
# breaking (### Removed / "(breaking)") -> skip; a major is a human call
|
||||
UNRELEASED=""
|
||||
if [ -f CHANGELOG.md ]; then
|
||||
UNRELEASED=$(awk '/^## \[Unreleased\]/{f=1; next} /^## \[/{f=0} f' CHANGELOG.md)
|
||||
fi
|
||||
if printf '%s\n' "$UNRELEASED" | grep -qiE '^### Removed|^### Changed \(breaking\)|BREAKING'; then
|
||||
echo "CHANGELOG [Unreleased] contains breaking changes — a major release is a human decision. Skipping."
|
||||
exit 0
|
||||
elif printf '%s\n' "$UNRELEASED" | grep -qE '^### (Added|Changed)'; then
|
||||
NEXT="v${major}.$((minor + 1)).0"
|
||||
KIND="minor (new features)"
|
||||
else
|
||||
NEXT="v${major}.${minor}.$((patch + 1))"
|
||||
KIND="patch (fixes/docs only)"
|
||||
fi
|
||||
echo "cutting: $NEXT — $KIND ($COUNT commits since $LATEST)"
|
||||
|
||||
git config user.name "loop release bot"
|
||||
git config user.email "noreply@users.noreply.github.com"
|
||||
git tag -a "$NEXT" -m "Release $NEXT — automated patch ($COUNT commits since $LATEST)"
|
||||
git tag -a "$NEXT" -m "Release $NEXT — automated $KIND ($COUNT commits since $LATEST)"
|
||||
git push "https://x-access-token:${RELEASE_TOKEN}@github.com/${REPO}.git" "$NEXT"
|
||||
echo "Pushed $NEXT."
|
||||
|
||||
@@ -8,7 +8,7 @@ name: "Loop: Triage"
|
||||
|
||||
on:
|
||||
workflow_run:
|
||||
workflows: ["Harness (E2E)", "Lint", "Run Tests"]
|
||||
workflows: ["Harness (E2E)", "Lint", "Run Tests", "govulncheck"]
|
||||
types: [completed]
|
||||
|
||||
permissions:
|
||||
|
||||
@@ -19,7 +19,7 @@ jobs:
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: 1.24
|
||||
go-version: "1.25"
|
||||
check-latest: true
|
||||
cache: true
|
||||
- name: Get dependencies
|
||||
@@ -56,7 +56,7 @@ jobs:
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: 1.24
|
||||
go-version: "1.25"
|
||||
check-latest: true
|
||||
cache: true
|
||||
- name: Get dependencies
|
||||
|
||||
+84
-3
@@ -5,9 +5,10 @@ All notable changes to Go Micro are documented here.
|
||||
Format follows [Keep a Changelog](https://keepachangelog.com/) and versions
|
||||
follow [Semantic Versioning](https://semver.org/), matching the git tags and
|
||||
[GitHub releases](https://github.com/micro/go-micro/releases) (`v6.MINOR.PATCH`).
|
||||
Patch releases are cut automatically as the loop merges improvements; the
|
||||
`[Unreleased]` section below is kept current between tags and rolled into the
|
||||
next version when it ships.
|
||||
Releases are cut automatically as the loop merges improvements — a **minor**
|
||||
bump when new features land (`### Added`/`### Changed`), a **patch** when it's
|
||||
fixes/docs only; major bumps stay a human decision. The `[Unreleased]` section
|
||||
below is kept current between tags and rolled into the next version when it ships.
|
||||
|
||||
> Earlier `2026.0x` headings are historical calendar-style markers from before
|
||||
> v6 tagging; they are kept for continuity and not reused.
|
||||
@@ -16,12 +17,92 @@ next version when it ships.
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Added
|
||||
- **First-agent guide chain contract** — the harness now verifies the install → demo → examples → 0→hero guide chain stays connected for new agent builders. (`internal/harness/`, `internal/website/docs/`)
|
||||
|
||||
### Fixed
|
||||
- **A2A fallback artifact text** — A2A fallback responses now avoid leaking provider artifact text into agent-visible output. (`gateway/a2a/`, `agent/`)
|
||||
- **Launch readiness notification replays** — launch-readiness notification replay paths now deduplicate repeated side effects. (`agent/`, `internal/harness/`)
|
||||
- **Plan-delegate harness cleanup** — plan/delegate harness cleanup is more reliable after conformance runs. (`internal/harness/`)
|
||||
- **AtlasCloud spoken notify replays** — AtlasCloud fallback handling now collapses spoken notification replays more consistently. (`ai/atlascloud/`, `agent/`)
|
||||
- **Agent-flow onboarding side effects** — onboarding side-effect checks are more stable across the agent-flow harness. (`agent/`, `internal/harness/`)
|
||||
|
||||
---
|
||||
|
||||
## [6.5.0] - July 2026
|
||||
|
||||
### Added
|
||||
- **Agent stream provider conformance** — provider conformance now covers agent streaming behavior so streaming-capable providers stay aligned with the harness contract. (`agent/`, `internal/harness/`)
|
||||
- **First-agent docs CLI parity check** — the harness now verifies first-agent docs commands match the CLI wayfinding surface. (`internal/harness/`, `internal/website/docs/`)
|
||||
- **Focused CLI inner-loop contract** — the local harness now covers scaffold, run/chat/inspect, and deploy dry-run boundaries in one first-run contract. (`internal/harness/`)
|
||||
- **First-agent wayfinding breadcrumbs** — first-agent docs and examples now have locked breadcrumb coverage from the README through the runnable examples. (`README.md`, `internal/website/docs/`, `examples/`)
|
||||
- **Offline `micro new` contract** — project scaffolding now has an offline contract so the first service path stays runnable without network access. (`cmd/micro/`, `internal/harness/`)
|
||||
|
||||
### Changed
|
||||
- **Provider model call timeouts** — model call timeout enforcement now wraps provider calls more defensively, reducing hangs in agent and harness paths. (`agent/`, `ai/`)
|
||||
- **First-agent harness diagnostics** — getting-started harness logs now make first-run and 0→hero failures easier to locate. (`internal/harness/`)
|
||||
- **MiniMax streaming conformance** — MiniMax streaming coverage now exercises broader provider conformance behavior. (`ai/minimax/`, `internal/harness/`)
|
||||
- **AtlasCloud streaming tool capability** — AtlasCloud tool-streaming capability detection is now aligned with provider fallback behavior. (`ai/atlascloud/`, `agent/`)
|
||||
|
||||
### Fixed
|
||||
- **Partial text tool calls** — text tool-call recovery now repairs partial function-style calls more reliably before fallback parsing continues. (`agent/`)
|
||||
- **Retry timeout test stability** — retry timeout coverage is less race-prone. (`agent/`)
|
||||
- **Checkpointed tool-call resume** — resumed agent runs now preserve checkpointed tool calls across startup resume paths. (`agent/`)
|
||||
- **Model retry backoff contracts** — retry backoff behavior now has focused contract coverage for model-call failures. (`agent/`, `ai/`)
|
||||
- **AtlasCloud conformance markers** — AtlasCloud fallback paths now preserve conformance markers through tool-call recovery. (`ai/atlascloud/`, `agent/`)
|
||||
- **AtlasCloud delegate text fallback** — delegate text fallback recovery is more reliable for AtlasCloud responses. (`ai/atlascloud/`, `agent/`)
|
||||
- **AtlasCloud incomplete plan repairs** — incomplete plan repair paths now recover more consistently in AtlasCloud fallback handling. (`ai/atlascloud/`, `agent/`)
|
||||
- **AtlasCloud partial text tool calls** — AtlasCloud fallback handling now repairs partial text-rendered tool calls more reliably. (`ai/atlascloud/`, `agent/`)
|
||||
|
||||
### Documentation
|
||||
- **Roadmap agent status** — public roadmap docs now reflect the current agent lifecycle status more consistently. (`internal/website/docs/`)
|
||||
- **Agent resume limits** — docs now describe checkpoint resume boundaries for agent runs. (`internal/website/docs/`)
|
||||
- **Zero-to-hero harness boundaries** — docs now clarify which 0→hero lifecycle checks are maintained by the local harness. (`internal/website/docs/`, `internal/harness/`)
|
||||
- **First-agent wayfinding guard** — first-agent docs wayfinding now has tighter guard coverage around the README, docs, and examples chain. (`README.md`, `internal/website/docs/`)
|
||||
|
||||
---
|
||||
|
||||
## [6.4.0] - July 2026
|
||||
|
||||
### Added
|
||||
- **Provider HTTP retry signals** — provider failures now preserve HTTP status and `Retry-After` details so retry classification and backoff can respond to rate limits and unavailable providers. (`ai/`)
|
||||
- **Zero-to-hero deploy dry-run verification** — the maintained 0→hero harness now covers deploy dry-run boundaries for the services → agents → workflows lifecycle. (`internal/harness/`)
|
||||
- **First-agent CLI wayfinding verification** — the harness now checks that first-agent CLI wayfinding stays discoverable. (`internal/harness/`)
|
||||
- **Agent startup resume verification** — agent startup resume now has focused checkpoint coverage. (`agent/`, `internal/harness/`)
|
||||
- **Direct first-agent chat prompts** — first-agent flows can accept direct chat prompts, reducing friction in the first useful conversation. (`cmd/micro/`, `agent/`)
|
||||
- **Workflow run info on tool spans** — agent tool spans now include workflow run details for easier trace correlation. (`agent/`, `flow/`)
|
||||
|
||||
### Fixed
|
||||
- **Stream fallback memory** — unsupported streaming attempts no longer leave stale duplicate user turns before fallback paths continue with non-streaming agent calls. (`agent/`)
|
||||
- **Function-style text tool calls** — agent fallback parsing now recognizes provider replies that render tools as function-style calls, including nested JSON arguments. (`agent/`)
|
||||
- **Plan/delegate notify recovery** — plan-delegate recovery now waits for recovered notify side effects and routes retries through the communications agent that owns the notification. (`internal/harness/`)
|
||||
- **Onboarding side-effect enforcement** — the agent-flow harness now fails when required onboarding side effects are missing, making lifecycle regressions visible. (`internal/harness/`)
|
||||
- **Plan/delegate notify stability** — notify recovery is more deterministic across retry and replay paths. (`agent/`, `internal/harness/`)
|
||||
- **AtlasCloud MiniMax tool fallback** — AtlasCloud MiniMax service-tool fallback now handles 400 responses and follow-up retries more reliably. (`ai/atlascloud/`, `agent/`)
|
||||
|
||||
### Documentation
|
||||
- **First-agent docs wayfinding guard** — the local harness now includes a focused no-network check for first-agent and 0→hero docs links. (`Makefile`, `internal/harness/`)
|
||||
|
||||
---
|
||||
|
||||
## [6.3.18] - July 2026
|
||||
|
||||
### Added
|
||||
- **StreamAsk close cancellation** — agent streaming calls now cancel promptly when their runner closes, avoiding orphaned stream work. (`agent/`)
|
||||
- **Agent resume pending helper** — agent durability now has a focused helper for resuming pending checkpointed runs. (`agent/`)
|
||||
- **Agent tool retry tracing** — agent traces now include tool retry attempts for easier debugging of retry/fallback behavior. (`agent/`)
|
||||
- **Shared-broker universe harness** — the universe harness now runs against the shared broker path, improving coverage of the same runtime wiring used by services, agents, and workflows. (`internal/harness/`)
|
||||
|
||||
### Fixed
|
||||
- **Plan/delegate retry idempotency** — agent retries now preserve side-effect and notification dedupe across conformance retry paths, including completion and owner-notification edge cases. (`agent/`, `internal/harness/`)
|
||||
- **AtlasCloud text tool calls** — AtlasCloud fallback handling now recovers more text-rendered tool calls from OpenAI-compatible responses. (`ai/atlascloud/`, `agent/`)
|
||||
- **OpenAI-compatible text tool calls** — OpenAI-compatible providers now recover text-rendered tool calls more reliably. (`agent/`)
|
||||
- **AtlasCloud multi-step follow-ups** — AtlasCloud tool fallback handling now continues multi-step tool follow-up paths more reliably. (`ai/atlascloud/`, `agent/`)
|
||||
|
||||
### Documentation
|
||||
- **Agent debugging quickcheck** — docs now include a focused quickcheck path for first-agent debugging. (`internal/website/docs/`)
|
||||
- **Website first-agent examples map** — website docs now link the maintained examples wayfinding map for the first-agent route. (`internal/website/docs/`)
|
||||
- **Examples wayfinding index** — examples docs now provide a central map for first-agent, support, and interop examples. (`examples/`, `internal/website/docs/`)
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ LDFLAGS = -X $(GIT_IMPORT).BuildDate=$(BUILD_DATE) -X $(GIT_IMPORT).GitCommit=$(
|
||||
# GORELEASER_DOCKER_IMAGE = ghcr.io/goreleaser/goreleaser-cross:v1.25.7
|
||||
GORELEASER_DOCKER_IMAGE = ghcr.io/goreleaser/goreleaser:latest
|
||||
|
||||
.PHONY: test test-race test-coverage harness docs-wayfinding install-smoke provider-conformance-mock provider-conformance lint fmt install-tools proto clean help gorelease-dry-run gorelease-dry-run-docker
|
||||
.PHONY: test test-race test-coverage harness inner-loop cli-wayfinding docs-wayfinding install-smoke provider-conformance-mock provider-conformance lint fmt install-tools proto clean help gorelease-dry-run gorelease-dry-run-docker
|
||||
|
||||
# Default target
|
||||
help:
|
||||
@@ -19,7 +19,9 @@ help:
|
||||
@echo " make test-coverage - Run tests with coverage"
|
||||
@echo " make lint - Run linter"
|
||||
@echo " make harness - Run deterministic getting-started and end-to-end harnesses"
|
||||
@echo " make docs-wayfinding - Verify first-agent docs wayfinding links resolve locally"
|
||||
@echo " make inner-loop - Verify scaffold → run/chat/inspect → deploy dry-run contract"
|
||||
@echo " make cli-wayfinding - Verify installed first-agent CLI wayfinding commands"
|
||||
@echo " make docs-wayfinding - Verify first-agent docs/CLI wayfinding stays in sync"
|
||||
@echo " make install-smoke - Verify the local install.sh and first-run CLI smoke path"
|
||||
@echo " make provider-conformance-mock - Run cross-provider harness with deterministic mock provider"
|
||||
@echo " make provider-conformance - Run harnesses against configured live providers"
|
||||
@@ -50,18 +52,36 @@ test-coverage:
|
||||
# This mirrors the default CI path so local dogfooding catches scaffold,
|
||||
# run/chat/inspect, and 0→hero regressions before a PR is opened.
|
||||
harness:
|
||||
$(MAKE) docs-wayfinding
|
||||
$(MAKE) install-smoke
|
||||
go test ./cmd/micro/cli/new -run TestZeroToOne -count=1
|
||||
$(MAKE) cli-wayfinding
|
||||
$(MAKE) inner-loop
|
||||
./internal/harness/zero-to-hero-ci/run.sh
|
||||
go run ./internal/harness/agent-flow
|
||||
$(MAKE) provider-conformance-mock
|
||||
|
||||
# Focused provider-free CLI inner-loop contract: scaffold a service, keep the
|
||||
# run/chat/inspect commands discoverable, and prove deploy dry-run reaches the
|
||||
# documented boundary without remote side effects. Use this when README/docs/CLI
|
||||
# drift is the concern and the full runtime harness is more than you need.
|
||||
inner-loop:
|
||||
go test ./cmd/micro/cli/new -run TestZeroToOne -count=1
|
||||
go test ./cmd/micro -run 'TestFirstAgentWalkthroughCLIBoundaries|TestZeroToHeroCLIBoundaries|TestZeroToHeroCommandPrintsMaintainedNoSecretPath' -count=1
|
||||
go test ./cmd/micro/cli/deploy -run TestDeployDryRun -count=1
|
||||
go test ./internal/harness/zero-to-hero-ci -run 'TestZeroToHeroDeployDryRunCommandSmoke|TestNoSecretFirstAgentDebuggingSmoke|TestYourFirstAgentTutorialSmoke' -count=1
|
||||
|
||||
# Verify the installed CLI keeps the first-agent on-ramp commands discoverable.
|
||||
# This guards the no-secret commands README/docs recommend (`micro agent demo`,
|
||||
# `micro examples`, and `micro zero-to-hero`) as a CI contract.
|
||||
cli-wayfinding:
|
||||
go test ./cmd/micro -run 'TestFirstAgentWalkthroughCLIBoundaries|TestExamplesWayfindingIndexStaysLinked|TestExamplesCommandPointsAtWayfindingIndex|TestZeroToHeroCommandPrintsMaintainedNoSecretPath' -count=1
|
||||
$(MAKE) docs-wayfinding
|
||||
$(MAKE) install-smoke
|
||||
|
||||
# Verify the README and website first-agent/0→hero wayfinding links resolve to
|
||||
# maintained local docs and examples. This is a focused no-network guard for the
|
||||
# developer-adoption on-ramp.
|
||||
docs-wayfinding:
|
||||
go test ./internal/harness/zero-to-hero-ci -run 'TestFirstAgentWayfindingDocs|TestFirstAgentWayfindingLinkTargetsResolve' -count=1
|
||||
go test ./internal/harness/zero-to-hero-ci -run 'TestFirstAgentWayfinding' -count=1
|
||||
go test ./cmd/micro -run 'TestFirstAgentDocsMatchCLIOutput|TestFirstAgentWalkthroughCLIBoundaries' -count=1
|
||||
|
||||
# Verify the documented install script and first-run CLI command boundaries without
|
||||
# provider keys or network access.
|
||||
|
||||
@@ -78,6 +78,12 @@ access or provider keys, use:
|
||||
make install-smoke
|
||||
```
|
||||
|
||||
To verify the focused CLI inner-loop contract — scaffold → run/chat/inspect → deploy dry-run — use:
|
||||
|
||||
```bash
|
||||
make inner-loop
|
||||
```
|
||||
|
||||
To run the broader local contract (including the [0→hero services → agents → workflows path](internal/website/docs/guides/zero-to-hero.md),
|
||||
chat/inspect CLI boundaries, and deploy dry-run), use:
|
||||
|
||||
@@ -92,18 +98,20 @@ walkable agent path in this order:
|
||||
|
||||
1. [Install troubleshooting](internal/website/docs/guides/install-troubleshooting.md) — verify the binary installer or `go install`, `PATH`, `micro --version`, and the no-secret smoke path before agent work.
|
||||
2. `micro agent demo` — print the provider-free first-agent demo command and next docs steps from the installed CLI.
|
||||
3. `micro examples` — print the maintained provider-free runnable examples in copy/paste order.
|
||||
4. `micro zero-to-hero` — print the maintained one-command no-secret lifecycle harness and runnable examples.
|
||||
5. [Examples wayfinding index](examples/INDEX.md) — choose the smallest no-secret first-agent, maintained [0→hero support reference](examples/support/), and next interop examples from one map.
|
||||
6. [Smallest first-agent example](examples/first-agent/) — run one service-backed agent with a mock model and no provider key.
|
||||
7. [No-secret first-agent transcript](internal/website/docs/guides/no-secret-first-agent.md) — run the
|
||||
3. `micro agent quickcheck` (or `micro agent debug`) — when scaffold → run → chat → inspect stalls, print the short recovery map before you dive into the full debugging guide.
|
||||
4. `micro examples` — print the maintained provider-free runnable examples in copy/paste order.
|
||||
5. `micro zero-to-hero` — print the maintained one-command no-secret lifecycle harness and runnable examples.
|
||||
6. [Examples wayfinding index](examples/INDEX.md) — choose the smallest no-secret first-agent, maintained [0→hero support reference](examples/support/), and next interop examples from one map.
|
||||
7. [Smallest first-agent example](examples/first-agent/) — run one service-backed agent with a mock model and no provider key.
|
||||
8. [No-secret first-agent transcript](internal/website/docs/guides/no-secret-first-agent.md) — run the
|
||||
maintained support agent with a mock model and see services → agents → workflows succeed without a key.
|
||||
8. [Your First Agent](internal/website/docs/guides/your-first-agent.md) — build a
|
||||
9. [Your First Agent](internal/website/docs/guides/your-first-agent.md) — build a
|
||||
service-backed agent and talk to it with `micro chat`.
|
||||
9. [Debugging your agent](internal/website/docs/guides/debugging-agents.md) — use
|
||||
`micro inspect agent <name>`, run history, memory, and provider checks when the first
|
||||
conversation does something unexpected.
|
||||
10. [0→hero Reference](internal/website/docs/guides/zero-to-hero.md) — complete the
|
||||
10. [Debugging your agent](internal/website/docs/guides/debugging-agents.md) — use
|
||||
`micro agent preflight` before `micro run`, `micro agent doctor` after `micro run`,
|
||||
then `micro chat` and `micro inspect agent <name>` to recover run history, memory,
|
||||
and provider checks when the first conversation does something unexpected.
|
||||
11. [0→hero Reference](internal/website/docs/guides/zero-to-hero.md) — complete the
|
||||
services → agents → workflows loop with scaffold, run, chat, inspect, flow
|
||||
history, and deploy dry-run commands that match the maintained harness.
|
||||
|
||||
|
||||
+18
-4
@@ -14,8 +14,9 @@ The full, current roadmap lives at **[go-micro.dev/docs/roadmap](https://go-micr
|
||||
|
||||
## Where we are (v6)
|
||||
|
||||
Services, agents (`plan`/`delegate`, guardrails, memory, tool middleware), durable
|
||||
flows, the MCP and A2A gateways (both directions, including A2A streaming,
|
||||
Services, agents (`plan`/`delegate`, guardrails, memory, tool middleware,
|
||||
checkpoint/resume, and OpenTelemetry run spans), durable flows, the MCP and A2A
|
||||
gateways (both directions, including A2A streaming,
|
||||
push notifications, and multi-turn continuation), x402 paid tools, secure by
|
||||
default.
|
||||
|
||||
@@ -39,11 +40,24 @@ default.
|
||||
propagation, retry/backoff.
|
||||
- **Getting-started contract** — define and CI-verify the 0→1 and 0→hero flows.
|
||||
|
||||
## Shipped agent depth
|
||||
|
||||
- **Durable agent loop** — opt-in `Checkpoint` support lets agent `Ask` and
|
||||
streaming runs persist, list pending work, and resume without replaying completed
|
||||
tool calls. Human-input pauses resume through explicit input helpers.
|
||||
- **Agent observability** — agent `RunInfo` now feeds OpenTelemetry spans/events
|
||||
across runs, model turns, tool calls, retries, delegation lineage, and resume
|
||||
checkpoints.
|
||||
|
||||
## Next — agentic depth
|
||||
|
||||
- **Durable agent loop** — resume a long run via `Checkpoint` (flows already do).
|
||||
- **Streaming** — broaden provider-backed `ai.Stream` coverage and keep chat/A2A streaming end to end.
|
||||
- **Agent observability** — `RunInfo` → OpenTelemetry spans.
|
||||
- **Resume operations polish** — keep improving CLI/docs breadcrumbs for finding
|
||||
pending agent runs and deciding whether to call resume, resume-input, or stream
|
||||
resume in production.
|
||||
- **Observability hardening** — keep span attributes and run inspection coherent
|
||||
across agents, flows, and gateways as more providers and workflow paths are
|
||||
exercised.
|
||||
|
||||
## Later
|
||||
|
||||
|
||||
+32
-3
@@ -33,6 +33,7 @@ import (
|
||||
_ "go-micro.dev/v6/ai/atlascloud"
|
||||
_ "go-micro.dev/v6/ai/gemini"
|
||||
_ "go-micro.dev/v6/ai/groq"
|
||||
_ "go-micro.dev/v6/ai/minimax"
|
||||
_ "go-micro.dev/v6/ai/mistral"
|
||||
_ "go-micro.dev/v6/ai/ollama"
|
||||
_ "go-micro.dev/v6/ai/openai"
|
||||
@@ -105,6 +106,11 @@ type agentImpl struct {
|
||||
// durable delegate-result cache is written.
|
||||
delegateMu sync.Mutex
|
||||
delegateCalls map[string]*delegateCall
|
||||
|
||||
// stopCh lets Stop unblock Run. Without this, tests and harnesses that
|
||||
// start agents in goroutines can leave Run parked forever after the RPC
|
||||
// server has been stopped.
|
||||
stopCh chan struct{}
|
||||
}
|
||||
|
||||
// New creates a new Agent.
|
||||
@@ -414,6 +420,15 @@ func (a *agentImpl) askLocked(ctx context.Context, runID, message, parentRunID s
|
||||
continue
|
||||
}
|
||||
}
|
||||
if toolName := partialTextToolCallName(resp.Reply, toolList); len(resp.ToolCalls) == 0 && toolName != "" && planCompletionTurn < maxPlanCompletionTurns {
|
||||
if resp.Reply != "" {
|
||||
a.mem.Add("assistant", resp.Reply)
|
||||
}
|
||||
message = fmt.Sprintf("Your previous response started a %q tool call but did not finish valid tool-call markup or JSON arguments, so no tool was executed. Retry the same step now by emitting one complete valid tool call for %q. Do not describe the action in prose, and do not claim completion until the tool call succeeds.", toolName, toolName)
|
||||
a.mem.Add("user", message)
|
||||
messages = a.mem.Messages()
|
||||
continue
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
@@ -432,9 +447,13 @@ func (a *agentImpl) askLocked(ctx context.Context, runID, message, parentRunID s
|
||||
reply += resp.Answer
|
||||
}
|
||||
|
||||
completedToolCalls := checkpointToolCalls(run.Steps)
|
||||
if a.currentRun != nil {
|
||||
completedToolCalls = checkpointToolCalls(a.currentRun.Steps)
|
||||
}
|
||||
res := &Response{
|
||||
Reply: reply,
|
||||
ToolCalls: resp.ToolCalls,
|
||||
ToolCalls: mergeCheckpointToolCalls(completedToolCalls, resp.ToolCalls),
|
||||
Agent: a.opts.Name,
|
||||
RunID: a.runID,
|
||||
ParentID: parentRunID,
|
||||
@@ -526,6 +545,11 @@ func (a *agentImpl) Run() error {
|
||||
return fmt.Errorf("failed to start agent: %w", err)
|
||||
}
|
||||
|
||||
stopCh := make(chan struct{})
|
||||
a.mu.Lock()
|
||||
a.stopCh = stopCh
|
||||
a.mu.Unlock()
|
||||
|
||||
fmt.Printf("Agent %s registered (manages: %s)\n", a.opts.Name, strings.Join(a.opts.Services, ", "))
|
||||
|
||||
// Optionally serve the agent directly over the A2A protocol, calling
|
||||
@@ -547,12 +571,17 @@ func (a *agentImpl) Run() error {
|
||||
fmt.Printf("Agent %s serving A2A on %s\n", a.opts.Name, a.opts.A2AAddress)
|
||||
}
|
||||
|
||||
ch := make(chan struct{})
|
||||
<-ch
|
||||
<-stopCh
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *agentImpl) Stop() error {
|
||||
a.mu.Lock()
|
||||
if a.stopCh != nil {
|
||||
close(a.stopCh)
|
||||
a.stopCh = nil
|
||||
}
|
||||
a.mu.Unlock()
|
||||
if a.server != nil {
|
||||
return a.server.Stop()
|
||||
}
|
||||
|
||||
@@ -38,6 +38,16 @@ func TestNew(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBundledProviderImportsIncludeMiniMaxForConformance(t *testing.T) {
|
||||
if model := ai.New("minimax", ai.WithAPIKey("test-key")); model == nil {
|
||||
t.Fatal("ai.New(\"minimax\") returned nil; agent live conformance cannot exercise MiniMax")
|
||||
}
|
||||
caps := ai.ProviderCapabilities("minimax")
|
||||
if !caps.Stream || !caps.ToolStream {
|
||||
t.Fatalf("MiniMax capabilities = %#v, want streaming and tool streaming registered", caps)
|
||||
}
|
||||
}
|
||||
|
||||
func TestChatResponseIncludesRunIDs(t *testing.T) {
|
||||
fakeGen = func(ctx context.Context, opts ai.Options, req *ai.Request) (*ai.Response, error) {
|
||||
return &ai.Response{Reply: "ok"}, nil
|
||||
|
||||
+16
-5
@@ -737,17 +737,28 @@ func normalizeDelegateTask(task string) string {
|
||||
}
|
||||
}, task)
|
||||
task = strings.Join(strings.Fields(task), " ")
|
||||
if strings.Contains(task, "notify") &&
|
||||
strings.Contains(task, "owner") &&
|
||||
if strings.Contains(task, "owner") &&
|
||||
strings.Contains(task, "acme") &&
|
||||
strings.Contains(task, "launch") &&
|
||||
strings.Contains(task, "plan") &&
|
||||
(strings.Contains(task, "ready") || strings.Contains(task, "readiness") || strings.Contains(task, "prepared") || strings.Contains(task, "complete")) {
|
||||
isLaunchReadinessDelegateTask(task) {
|
||||
return "notify owner@acme.com launch-plan-ready"
|
||||
}
|
||||
return task
|
||||
}
|
||||
|
||||
func isLaunchReadinessDelegateTask(task string) bool {
|
||||
hasNotify := strings.Contains(task, "notify") || strings.Contains(task, "notification") || strings.Contains(task, "tell")
|
||||
hasLaunch := strings.Contains(task, "launch")
|
||||
hasPlanOrReadiness := strings.Contains(task, "plan") || strings.Contains(task, "readiness") || strings.Contains(task, "ready")
|
||||
hasCompletion := strings.Contains(task, "ready") ||
|
||||
strings.Contains(task, "readiness") ||
|
||||
strings.Contains(task, "prepared") ||
|
||||
strings.Contains(task, "complete") ||
|
||||
strings.Contains(task, "finished") ||
|
||||
strings.Contains(task, "done") ||
|
||||
strings.Contains(task, "sent")
|
||||
return hasNotify && hasLaunch && hasPlanOrReadiness && hasCompletion
|
||||
}
|
||||
|
||||
// isAgent reports whether name resolves to a registered agent (a
|
||||
// service advertising type=agent in its metadata).
|
||||
func (a *agentImpl) isAgent(name string) bool {
|
||||
|
||||
+14
-9
@@ -196,16 +196,21 @@ func TestDelegateResultCacheReusesLaunchReadinessParaphrases(t *testing.T) {
|
||||
t.Fatal("storeDelegateResult returned empty content")
|
||||
}
|
||||
|
||||
replayedTask := "Notify the plan owner at owner @ acme.com that launch readiness is prepared and complete."
|
||||
cached, ok := a.cachedDelegateResult("delegate-2", " COMMS ", replayedTask)
|
||||
if !ok {
|
||||
t.Fatal("cachedDelegateResult missed equivalent launch-readiness delegate replay")
|
||||
replayedTasks := []string{
|
||||
"Notify the plan owner at owner @ acme.com that launch readiness is prepared and complete.",
|
||||
"Tell owner at acme dot com the launch readiness notification was sent and the plan is done.",
|
||||
}
|
||||
if cached.ID != "delegate-2" {
|
||||
t.Fatalf("cached result ID = %q, want replay call ID", cached.ID)
|
||||
}
|
||||
if !containsStr(cached.Content, "Notified owner@acme.com") {
|
||||
t.Fatalf("cached result content = %q, want original delegate reply", cached.Content)
|
||||
for i, replayedTask := range replayedTasks {
|
||||
cached, ok := a.cachedDelegateResult("delegate-replay", " COMMS ", replayedTask)
|
||||
if !ok {
|
||||
t.Fatalf("cachedDelegateResult missed equivalent launch-readiness delegate replay %d", i)
|
||||
}
|
||||
if cached.ID != "delegate-replay" {
|
||||
t.Fatalf("cached result ID = %q, want replay call ID", cached.ID)
|
||||
}
|
||||
if !containsStr(cached.Content, "Notified owner@acme.com") {
|
||||
t.Fatalf("cached result content = %q, want original delegate reply", cached.Content)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+70
-12
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"go-micro.dev/v6/ai"
|
||||
@@ -234,28 +235,32 @@ func agentOperationalError(err error) error {
|
||||
|
||||
func (a *agentImpl) checkpointToolWrap(next ai.ToolHandler) ai.ToolHandler {
|
||||
return func(ctx context.Context, call ai.ToolCall) ai.ToolResult {
|
||||
if a.opts.Checkpoint == nil || a.currentRun == nil {
|
||||
run := a.currentRun
|
||||
if a.opts.Checkpoint == nil || run == nil {
|
||||
return next(ctx, call)
|
||||
}
|
||||
name := toolCheckpointName(call)
|
||||
if rec, ok := findStep(a.currentRun.Steps, name); ok && rec.Status == "done" {
|
||||
if rec, ok := findStep(run.Steps, name); ok && rec.Status == "done" {
|
||||
return ai.ToolResult{ID: call.ID, Value: rec.Result, Content: rec.Result}
|
||||
}
|
||||
|
||||
idx := upsertStep(&a.currentRun.Steps, flow.StepRecord{Name: name, Status: "in_progress"})
|
||||
_ = a.saveRun(ctx, *a.currentRun)
|
||||
idx := upsertStep(&run.Steps, flow.StepRecord{Name: name, Status: "in_progress"})
|
||||
_ = a.saveRun(ctx, *run)
|
||||
res := next(ctx, call)
|
||||
a.currentRun.Steps[idx].Attempts++
|
||||
if idx < 0 || idx >= len(run.Steps) || run.Steps[idx].Name != name {
|
||||
idx = upsertStep(&run.Steps, flow.StepRecord{Name: name, Status: "in_progress"})
|
||||
}
|
||||
run.Steps[idx].Attempts++
|
||||
if res.Refused != "" {
|
||||
a.currentRun.Steps[idx].Status = "failed"
|
||||
a.currentRun.Steps[idx].Error = res.Content
|
||||
_ = a.saveRun(ctx, *a.currentRun)
|
||||
run.Steps[idx].Status = "failed"
|
||||
run.Steps[idx].Error = res.Content
|
||||
_ = a.saveRun(ctx, *run)
|
||||
return res
|
||||
}
|
||||
a.currentRun.Steps[idx].Status = "done"
|
||||
a.currentRun.Steps[idx].Result = res.Content
|
||||
a.currentRun.Steps[idx].Error = ""
|
||||
_ = a.saveRun(ctx, *a.currentRun)
|
||||
run.Steps[idx].Status = "done"
|
||||
run.Steps[idx].Result = res.Content
|
||||
run.Steps[idx].Error = ""
|
||||
_ = a.saveRun(ctx, *run)
|
||||
return res
|
||||
}
|
||||
}
|
||||
@@ -288,3 +293,56 @@ func upsertStep(steps *[]flow.StepRecord, rec flow.StepRecord) int {
|
||||
*steps = append(*steps, rec)
|
||||
return len(*steps) - 1
|
||||
}
|
||||
|
||||
func checkpointToolCalls(steps []flow.StepRecord) []ai.ToolCall {
|
||||
calls := make([]ai.ToolCall, 0, len(steps))
|
||||
for _, step := range steps {
|
||||
call, ok := checkpointToolCall(step)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
calls = append(calls, call)
|
||||
}
|
||||
return calls
|
||||
}
|
||||
|
||||
func checkpointToolCall(step flow.StepRecord) (ai.ToolCall, bool) {
|
||||
if step.Status != "done" || !strings.HasPrefix(step.Name, "tool:") {
|
||||
return ai.ToolCall{}, false
|
||||
}
|
||||
parts := strings.SplitN(strings.TrimPrefix(step.Name, "tool:"), ":", 2)
|
||||
if len(parts) != 2 || parts[0] == "" {
|
||||
return ai.ToolCall{}, false
|
||||
}
|
||||
input := map[string]any{}
|
||||
if parts[1] != "null" && parts[1] != "" {
|
||||
if err := json.Unmarshal([]byte(parts[1]), &input); err != nil {
|
||||
return ai.ToolCall{}, false
|
||||
}
|
||||
}
|
||||
return ai.ToolCall{Name: parts[0], Input: input, Result: step.Result}, true
|
||||
}
|
||||
|
||||
func mergeCheckpointToolCalls(checkpointed, current []ai.ToolCall) []ai.ToolCall {
|
||||
if len(checkpointed) == 0 {
|
||||
return current
|
||||
}
|
||||
seen := make(map[string]struct{}, len(current))
|
||||
for _, call := range current {
|
||||
seen[toolCallKey(call.Name, call.Input)] = struct{}{}
|
||||
}
|
||||
merged := make([]ai.ToolCall, 0, len(checkpointed)+len(current))
|
||||
for _, call := range checkpointed {
|
||||
if _, ok := seen[toolCallKey(call.Name, call.Input)]; ok {
|
||||
continue
|
||||
}
|
||||
merged = append(merged, call)
|
||||
}
|
||||
merged = append(merged, current...)
|
||||
return merged
|
||||
}
|
||||
|
||||
func toolCallKey(name string, input map[string]any) string {
|
||||
b, _ := json.Marshal(input)
|
||||
return name + ":" + string(b)
|
||||
}
|
||||
|
||||
+114
-1
@@ -21,7 +21,7 @@ func TestResumeCompletedCheckpointDoesNotReplayModel(t *testing.T) {
|
||||
calls := 0
|
||||
fakeGen = func(ctx context.Context, opts ai.Options, req *ai.Request) (*ai.Response, error) {
|
||||
calls++
|
||||
return &ai.Response{Reply: "done"}, nil
|
||||
return &ai.Response{Reply: "done", ToolCalls: []ai.ToolCall{{ID: "call-1", Name: "external.lookup", Result: "cached"}}}, nil
|
||||
}
|
||||
defer func() { fakeGen = nil }()
|
||||
|
||||
@@ -49,6 +49,9 @@ func TestResumeCompletedCheckpointDoesNotReplayModel(t *testing.T) {
|
||||
if resumed.RunID != resp.RunID {
|
||||
t.Fatalf("resumed run id = %q, want %q", resumed.RunID, resp.RunID)
|
||||
}
|
||||
if len(resumed.ToolCalls) != 1 || resumed.ToolCalls[0].Name != "external.lookup" || resumed.ToolCalls[0].Result != "cached" {
|
||||
t.Fatalf("resumed tool calls = %#v, want persisted completed call", resumed.ToolCalls)
|
||||
}
|
||||
if calls != 1 {
|
||||
t.Fatalf("model calls after Resume = %d, want 1", calls)
|
||||
}
|
||||
@@ -101,6 +104,12 @@ func TestResumeFailedCheckpointDoesNotReplayCompletedTool(t *testing.T) {
|
||||
if resp.Reply != "finished from checkpoint" {
|
||||
t.Fatalf("Resume reply = %q", resp.Reply)
|
||||
}
|
||||
if len(resp.ToolCalls) != 1 || resp.ToolCalls[0].Name != "external.charge" || resp.ToolCalls[0].Result != "charged" {
|
||||
t.Fatalf("resumed tool calls = %#v, want preserved completed charge call", resp.ToolCalls)
|
||||
}
|
||||
if got := resp.ToolCalls[0].Input["order"]; got != "42" {
|
||||
t.Fatalf("resumed tool input order = %#v, want 42", got)
|
||||
}
|
||||
if toolRuns != 1 {
|
||||
t.Fatalf("tool executions after Resume = %d, want completed tool was not replayed", toolRuns)
|
||||
}
|
||||
@@ -145,6 +154,45 @@ func TestCheckpointSkipsDuplicateToolWithinAsk(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckpointToolWrapSurvivesClearedCurrentRun(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
cp := flow.StoreCheckpoint(store.NewMemoryStore(), "tool-cleared-run-agent")
|
||||
run := flow.Run{
|
||||
ID: "run-1",
|
||||
Flow: "tool-cleared-run-agent",
|
||||
Status: "running",
|
||||
Steps: []flow.StepRecord{{Name: agentAskStep, Status: "in_progress"}},
|
||||
}
|
||||
a := &agentImpl{
|
||||
opts: newOptions(Name("tool-cleared-run-agent"), WithCheckpoint(cp)),
|
||||
currentRun: &run,
|
||||
}
|
||||
|
||||
handler := a.checkpointToolWrap(func(context.Context, ai.ToolCall) ai.ToolResult {
|
||||
a.currentRun = nil
|
||||
return ai.ToolResult{ID: "call-1", Content: "created"}
|
||||
})
|
||||
res := handler(ctx, ai.ToolCall{ID: "call-1", Name: "external.create", Input: map[string]any{"title": "Design"}})
|
||||
if res.Content != "created" {
|
||||
t.Fatalf("tool result = %q, want created", res.Content)
|
||||
}
|
||||
|
||||
loaded, ok, err := cp.Load(ctx, "run-1")
|
||||
if err != nil {
|
||||
t.Fatalf("load checkpoint: %v", err)
|
||||
}
|
||||
if !ok {
|
||||
t.Fatal("checkpoint missing")
|
||||
}
|
||||
rec, ok := findStep(loaded.Steps, `tool:external.create:{"title":"Design"}`)
|
||||
if !ok {
|
||||
t.Fatalf("checkpoint steps = %#v, want completed tool step", loaded.Steps)
|
||||
}
|
||||
if rec.Status != "done" || rec.Result != "created" || rec.Attempts != 1 {
|
||||
t.Fatalf("tool checkpoint = %#v, want done result with one attempt", rec)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckpointContinuesRunWithUnfinishedPlanStep(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
cp := flow.StoreCheckpoint(store.NewMemoryStore(), "unfinished-plan-agent")
|
||||
@@ -397,6 +445,71 @@ func TestResumeFailedCheckpointAfterFreshAgentRestart(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestResumePendingAfterFreshAgentRestartDoesNotReplayCompletedTool(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
st := store.NewMemoryStore()
|
||||
cp := flow.StoreCheckpoint(st, "startup-resume-agent")
|
||||
toolRuns := 0
|
||||
failFirst := true
|
||||
fakeGen = func(ctx context.Context, opts ai.Options, req *ai.Request) (*ai.Response, error) {
|
||||
if opts.ToolHandler != nil {
|
||||
res := opts.ToolHandler(ctx, ai.ToolCall{ID: "call-1", Name: "external.allocate", Input: map[string]any{"cluster": "blue"}})
|
||||
if res.Content != "allocated" {
|
||||
t.Fatalf("tool result = %q, want allocated", res.Content)
|
||||
}
|
||||
}
|
||||
if failFirst {
|
||||
failFirst = false
|
||||
return nil, errors.New("process stopped before final response")
|
||||
}
|
||||
return &ai.Response{Reply: "startup recovery complete"}, nil
|
||||
}
|
||||
defer func() { fakeGen = nil }()
|
||||
|
||||
newAgent := func() *agentImpl {
|
||||
return newTestAgent(Name("startup-resume-agent"), WithStore(st), WithCheckpoint(cp),
|
||||
WithTool("external.allocate", "allocate capacity once", nil, func(context.Context, map[string]any) (string, error) {
|
||||
toolRuns++
|
||||
return "allocated", nil
|
||||
}))
|
||||
}
|
||||
|
||||
first := newAgent()
|
||||
_, err := first.Ask(ctx, "allocate blue capacity")
|
||||
if err == nil {
|
||||
t.Fatal("Ask succeeded, want simulated process stop")
|
||||
}
|
||||
if toolRuns != 1 {
|
||||
t.Fatalf("tool executions after failed Ask = %d, want 1", toolRuns)
|
||||
}
|
||||
|
||||
restarted := newAgent()
|
||||
failedRun, err := ResumePending(ctx, restarted)
|
||||
if err != nil {
|
||||
t.Fatalf("ResumePending after restart: failedRun=%q err=%v", failedRun, err)
|
||||
}
|
||||
if failedRun != "" {
|
||||
t.Fatalf("failed run = %q, want none", failedRun)
|
||||
}
|
||||
if toolRuns != 1 {
|
||||
t.Fatalf("tool executions after ResumePending = %d, want completed tool not replayed", toolRuns)
|
||||
}
|
||||
runs, err := Pending(ctx, restarted)
|
||||
if err != nil {
|
||||
t.Fatalf("Pending after ResumePending: %v", err)
|
||||
}
|
||||
if len(runs) != 0 {
|
||||
t.Fatalf("Pending after ResumePending = %#v, want none", runs)
|
||||
}
|
||||
summaries, err := ListRunSummaries(st, "startup-resume-agent")
|
||||
if err != nil {
|
||||
t.Fatalf("ListRunSummaries after ResumePending: %v", err)
|
||||
}
|
||||
if len(summaries) != 1 || summaries[0].Status != "done" || summaries[0].Checkpoint != "done" {
|
||||
t.Fatalf("summary after ResumePending = %#v, want one done run", summaries)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResumeFailedCheckpointDoesNotDuplicateCompactedMemory(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
st := store.NewMemoryStore()
|
||||
|
||||
+229
-11
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -21,17 +22,20 @@ type conformanceProvider struct {
|
||||
live bool
|
||||
}
|
||||
|
||||
var agentConformanceProviders = []conformanceProvider{
|
||||
{name: "fake"},
|
||||
{name: "openai", key: "OPENAI_API_KEY", model: "GO_MICRO_CONFORMANCE_OPENAI_MODEL", live: true},
|
||||
{name: "anthropic", key: "ANTHROPIC_API_KEY", model: "GO_MICRO_CONFORMANCE_ANTHROPIC_MODEL", live: true},
|
||||
{name: "atlascloud", key: "ATLASCLOUD_API_KEY", model: "GO_MICRO_CONFORMANCE_ATLASCLOUD_MODEL", live: true},
|
||||
{name: "gemini", key: "GEMINI_API_KEY", model: "GO_MICRO_CONFORMANCE_GEMINI_MODEL", live: true},
|
||||
{name: "groq", key: "GROQ_API_KEY", model: "GO_MICRO_CONFORMANCE_GROQ_MODEL", live: true},
|
||||
{name: "minimax", key: "MINIMAX_API_KEY", model: "GO_MICRO_CONFORMANCE_MINIMAX_MODEL", live: true},
|
||||
{name: "mistral", key: "MISTRAL_API_KEY", model: "GO_MICRO_CONFORMANCE_MISTRAL_MODEL", live: true},
|
||||
{name: "together", key: "TOGETHER_API_KEY", model: "GO_MICRO_CONFORMANCE_TOGETHER_MODEL", live: true},
|
||||
}
|
||||
|
||||
func TestAgentProviderConformanceMatrix(t *testing.T) {
|
||||
providers := []conformanceProvider{
|
||||
{name: "fake"},
|
||||
{name: "openai", key: "OPENAI_API_KEY", model: "GO_MICRO_CONFORMANCE_OPENAI_MODEL", live: true},
|
||||
{name: "anthropic", key: "ANTHROPIC_API_KEY", model: "GO_MICRO_CONFORMANCE_ANTHROPIC_MODEL", live: true},
|
||||
{name: "atlascloud", key: "ATLASCLOUD_API_KEY", model: "GO_MICRO_CONFORMANCE_ATLASCLOUD_MODEL", live: true},
|
||||
{name: "gemini", key: "GEMINI_API_KEY", model: "GO_MICRO_CONFORMANCE_GEMINI_MODEL", live: true},
|
||||
{name: "groq", key: "GROQ_API_KEY", model: "GO_MICRO_CONFORMANCE_GROQ_MODEL", live: true},
|
||||
{name: "mistral", key: "MISTRAL_API_KEY", model: "GO_MICRO_CONFORMANCE_MISTRAL_MODEL", live: true},
|
||||
{name: "together", key: "TOGETHER_API_KEY", model: "GO_MICRO_CONFORMANCE_TOGETHER_MODEL", live: true},
|
||||
}
|
||||
providers := agentConformanceProviders
|
||||
|
||||
selected := selectedConformanceProviders(os.Getenv("GO_MICRO_AGENT_CONFORMANCE_PROVIDERS"))
|
||||
for _, provider := range providers {
|
||||
@@ -45,6 +49,151 @@ func TestAgentProviderConformanceMatrix(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAgentProviderStreamConformanceMatrix(t *testing.T) {
|
||||
providers := streamConformanceProviders()
|
||||
|
||||
selected := selectedConformanceProviders(os.Getenv("GO_MICRO_AGENT_CONFORMANCE_PROVIDERS"))
|
||||
for _, provider := range providers {
|
||||
provider := provider
|
||||
if len(selected) > 0 && !selected[provider.name] {
|
||||
continue
|
||||
}
|
||||
t.Run(provider.name, func(t *testing.T) {
|
||||
runAgentStreamConformanceScenario(t, provider)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func streamConformanceProviders() []conformanceProvider {
|
||||
providers := make([]conformanceProvider, 0, len(agentConformanceProviders))
|
||||
for _, provider := range agentConformanceProviders {
|
||||
// Gemini is covered by the non-streaming agent/tool matrix, but does not
|
||||
// currently advertise streaming in the provider capability registry.
|
||||
if provider.name == "gemini" {
|
||||
continue
|
||||
}
|
||||
providers = append(providers, provider)
|
||||
}
|
||||
return providers
|
||||
}
|
||||
|
||||
func TestAgentProviderConformanceMatrixIncludesEveryLiveProvider(t *testing.T) {
|
||||
want := map[string]string{
|
||||
"openai": "OPENAI_API_KEY",
|
||||
"anthropic": "ANTHROPIC_API_KEY",
|
||||
"atlascloud": "ATLASCLOUD_API_KEY",
|
||||
"gemini": "GEMINI_API_KEY",
|
||||
"groq": "GROQ_API_KEY",
|
||||
"minimax": "MINIMAX_API_KEY",
|
||||
"mistral": "MISTRAL_API_KEY",
|
||||
"together": "TOGETHER_API_KEY",
|
||||
}
|
||||
got := map[string]string{}
|
||||
for _, provider := range agentConformanceProviders {
|
||||
if provider.live {
|
||||
got[provider.name] = provider.key
|
||||
}
|
||||
}
|
||||
for name, key := range want {
|
||||
if got[name] != key {
|
||||
t.Fatalf("agentConformanceProviders[%q] key = %q, want %q", name, got[name], key)
|
||||
}
|
||||
}
|
||||
if len(got) != len(want) {
|
||||
t.Fatalf("agentConformanceProviders live providers = %#v, want exactly %#v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func runAgentStreamConformanceScenario(t *testing.T, provider conformanceProvider) {
|
||||
t.Helper()
|
||||
if provider.live {
|
||||
if os.Getenv(provider.key) == "" {
|
||||
t.Skipf("%s not set; skipping live %s stream conformance", provider.key, provider.name)
|
||||
}
|
||||
if os.Getenv("GO_MICRO_AGENT_CONFORMANCE_LIVE") == "" {
|
||||
t.Skipf("GO_MICRO_AGENT_CONFORMANCE_LIVE not set; skipping live %s stream conformance", provider.name)
|
||||
}
|
||||
caps := ai.ProviderCapabilities(provider.name)
|
||||
if !caps.Stream {
|
||||
t.Fatalf("ProviderCapabilities(%q).Stream = false, want true for stream conformance", provider.name)
|
||||
}
|
||||
if !caps.ToolStream {
|
||||
t.Skipf("ProviderCapabilities(%q).ToolStream = false; skipping live tool stream conformance", provider.name)
|
||||
}
|
||||
} else {
|
||||
var sawToolSchema bool
|
||||
fakeStream = func(ctx context.Context, opts ai.Options, req *ai.Request) (ai.Stream, error) {
|
||||
if req.Prompt != "Stream exactly: agent-stream-conformance-ok" {
|
||||
return nil, fmt.Errorf("prompt = %q", req.Prompt)
|
||||
}
|
||||
if len(req.Messages) == 0 || req.Messages[len(req.Messages)-1].Role != "user" || req.Messages[len(req.Messages)-1].Content != req.Prompt {
|
||||
return nil, fmt.Errorf("messages = %#v, want current user turn", req.Messages)
|
||||
}
|
||||
for _, tool := range req.Tools {
|
||||
if tool.Name == "conformance_echo" {
|
||||
sawToolSchema = true
|
||||
}
|
||||
}
|
||||
if !sawToolSchema {
|
||||
return nil, errors.New("stream request omitted conformance tool schema")
|
||||
}
|
||||
return &sliceStream{chunks: []string{"agent-stream-", "conformance-ok"}}, nil
|
||||
}
|
||||
defer func() { fakeStream = nil }()
|
||||
}
|
||||
|
||||
agentOpts := []Option{
|
||||
Name("stream-conformance-" + provider.name),
|
||||
Provider(provider.name),
|
||||
APIKey(os.Getenv(provider.key)),
|
||||
Prompt("Stream conformance: preserve the exact requested marker in the final answer."),
|
||||
WithRegistry(registry.NewMemoryRegistry()),
|
||||
WithStore(store.NewMemoryStore()),
|
||||
WithMemory(NewInMemory(8)),
|
||||
ModelCallTimeout(45 * time.Second),
|
||||
WithTool("conformance_echo", "Echo a conformance value and return a deterministic marker.", map[string]any{
|
||||
"value": map[string]any{"type": "string", "description": "value to echo"},
|
||||
}, func(ctx context.Context, input map[string]any) (string, error) {
|
||||
return `{"marker":"agent-stream-conformance-ok"}`, nil
|
||||
}),
|
||||
}
|
||||
if provider.model != "" {
|
||||
if model := os.Getenv(provider.model); model != "" {
|
||||
agentOpts = append(agentOpts, Model(model))
|
||||
}
|
||||
}
|
||||
|
||||
stream, err := New(agentOpts...).Stream(context.Background(), "Stream exactly: agent-stream-conformance-ok")
|
||||
if err != nil {
|
||||
t.Fatalf("Stream: %v", err)
|
||||
}
|
||||
defer stream.Close()
|
||||
|
||||
var reply strings.Builder
|
||||
deadline := time.After(45 * time.Second)
|
||||
for {
|
||||
select {
|
||||
case <-deadline:
|
||||
t.Fatal("timed out waiting for streamed final output")
|
||||
default:
|
||||
}
|
||||
chunk, err := stream.Recv()
|
||||
if errors.Is(err, io.EOF) {
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("Recv: %v", err)
|
||||
}
|
||||
reply.WriteString(chunk.Reply)
|
||||
if strings.Contains(reply.String(), "agent-stream-conformance-ok") {
|
||||
return
|
||||
}
|
||||
}
|
||||
if got := reply.String(); !strings.Contains(got, "agent-stream-conformance-ok") {
|
||||
t.Fatalf("streamed reply %q does not include conformance marker", got)
|
||||
}
|
||||
}
|
||||
|
||||
func selectedConformanceProviders(csv string) map[string]bool {
|
||||
out := map[string]bool{}
|
||||
for _, part := range strings.Split(csv, ",") {
|
||||
@@ -287,6 +436,20 @@ func TestAgentProviderConformanceFinalDelegateRetryUsesTaggedCall(t *testing.T)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAgentProviderConformanceMarkerRetryRequiresExactMarkerReply(t *testing.T) {
|
||||
prompt := nextConformanceRetryPrompt(true, true, false, 2)
|
||||
for _, want := range []string{
|
||||
"omitted the conformance marker",
|
||||
"do not call more tools",
|
||||
"do not summarize",
|
||||
"Reply with exactly this sentence: agent-conformance-ok after guarded delegate refusal.",
|
||||
} {
|
||||
if !strings.Contains(prompt, want) {
|
||||
t.Fatalf("marker retry prompt %q missing %q", prompt, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func nextConformanceRetryPrompt(sawTool, sawBlockedDelegate, hasMarker bool, attempt int) string {
|
||||
if attempt >= 4 && sawTool && !sawBlockedDelegate {
|
||||
return "Final conformance retry: emit exactly this tagged tool call so the harness can execute the guarded delegate refusal, then include agent-conformance-ok and the refusal in the final answer: " + conformanceDelegateTaggedCall
|
||||
@@ -297,7 +460,7 @@ func nextConformanceRetryPrompt(sawTool, sawBlockedDelegate, hasMarker bool, att
|
||||
case !sawBlockedDelegate:
|
||||
return "The previous response called conformance_echo but did not attempt the required guarded delegation. Continue the same conformance check now: call delegate exactly once with input " + conformanceDelegateInputJSON + "; do not answer in prose until that delegate call has been attempted. If native tool_calls are unavailable, emit exactly " + conformanceDelegateTaggedCall + ". The delegate is expected to be refused by policy; include that refusal and the agent-conformance marker in the final answer."
|
||||
case !hasMarker:
|
||||
return "The previous response completed the required tool calls but omitted the conformance marker. Continue the same conformance check now: do not call more tools; answer with the prior echo result marker agent-conformance-ok and mention the guarded delegate refusal."
|
||||
return "The previous response completed the required tool calls but omitted the conformance marker. Continue the same conformance check now: do not call more tools, do not summarize, and do not use synonyms. Reply with exactly this sentence: agent-conformance-ok after guarded delegate refusal."
|
||||
default:
|
||||
return "Retry the provider conformance check and include the agent-conformance marker in the final answer."
|
||||
}
|
||||
@@ -617,6 +780,61 @@ func TestAgentExecutesProviderTextToolCallFallback(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAgentRepairsPartialTextToolCallFallback(t *testing.T) {
|
||||
attempts := 0
|
||||
fakeGen = func(ctx context.Context, opts ai.Options, req *ai.Request) (*ai.Response, error) {
|
||||
if opts.ToolHandler == nil {
|
||||
return nil, errors.New("missing tool handler")
|
||||
}
|
||||
attempts++
|
||||
if attempts == 1 {
|
||||
return &ai.Response{Reply: `<tool_call name="conformance_echo">`}, nil
|
||||
}
|
||||
if !strings.Contains(req.Prompt, "did not finish valid tool-call markup") {
|
||||
return nil, fmt.Errorf("repair prompt = %q, want partial tool-call repair guidance", req.Prompt)
|
||||
}
|
||||
return &ai.Response{
|
||||
Reply: `<tool_call name="conformance_echo">{"value":"agent-conformance"}</tool_call>`,
|
||||
}, nil
|
||||
}
|
||||
defer func() { fakeGen = nil }()
|
||||
|
||||
var sawTool bool
|
||||
a := New(
|
||||
Name("conformance-partial-text-tool"),
|
||||
Provider("fake"),
|
||||
WithRegistry(registry.NewMemoryRegistry()),
|
||||
WithStore(store.NewMemoryStore()),
|
||||
WithMemory(NewInMemory(4)),
|
||||
WithTool("conformance_echo", "Echo a conformance value.", map[string]any{
|
||||
"value": map[string]any{"type": "string"},
|
||||
}, func(ctx context.Context, input map[string]any) (string, error) {
|
||||
sawTool = true
|
||||
if input["value"] != "agent-conformance" {
|
||||
return "", fmt.Errorf("unexpected value %v", input["value"])
|
||||
}
|
||||
return `{"marker":"agent-conformance-ok"}`, nil
|
||||
}),
|
||||
)
|
||||
|
||||
resp, err := a.Ask(context.Background(), "Run the partial text tool call fallback.")
|
||||
if err != nil {
|
||||
t.Fatalf("Ask: %v", err)
|
||||
}
|
||||
if attempts != 2 {
|
||||
t.Fatalf("attempts = %d, want repair retry", attempts)
|
||||
}
|
||||
if !sawTool {
|
||||
t.Fatal("repaired text tool call fallback did not execute the tool")
|
||||
}
|
||||
if len(resp.ToolCalls) != 1 || resp.ToolCalls[0].Name != "conformance_echo" {
|
||||
t.Fatalf("ToolCalls = %+v, want conformance_echo", resp.ToolCalls)
|
||||
}
|
||||
if !strings.Contains(resp.Reply, "agent-conformance-ok") {
|
||||
t.Fatalf("Reply = %q, want tool result marker", resp.Reply)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAgentExecutesTextToolCallFallbackAfterStructuredToolCall(t *testing.T) {
|
||||
fakeGen = func(ctx context.Context, opts ai.Options, req *ai.Request) (*ai.Response, error) {
|
||||
if opts.ToolHandler == nil {
|
||||
|
||||
@@ -68,6 +68,8 @@ func init() {
|
||||
_ = m.Init(opts...)
|
||||
return m
|
||||
})
|
||||
ai.RegisterStream("fake")
|
||||
ai.RegisterToolStream("fake")
|
||||
}
|
||||
|
||||
// fakeClient embeds the default client (so NewRequest works) and
|
||||
|
||||
+3
-2
@@ -374,13 +374,14 @@ func (a *agentImpl) traceTool(next ai.ToolHandler) ai.ToolHandler {
|
||||
return res
|
||||
}
|
||||
|
||||
ctx, span := a.tracer().Start(ctx, spanNameToolCall, trace.WithAttributes(
|
||||
spanAttrs := appendRunInfoAttributes([]attribute.KeyValue{
|
||||
attribute.String(AttrRunID, info.RunID),
|
||||
attribute.String(AttrParentRunID, info.ParentID),
|
||||
attribute.String(AttrAgentName, info.Agent),
|
||||
attribute.String(AttrToolName, call.Name),
|
||||
attribute.Bool(AttrDelegate, call.Name == toolDelegate),
|
||||
))
|
||||
}, info)
|
||||
ctx, span := a.tracer().Start(ctx, spanNameToolCall, trace.WithAttributes(spanAttrs...))
|
||||
res := next(ctx, call)
|
||||
dur := time.Since(start).Milliseconds()
|
||||
attrs := []attribute.KeyValue{attribute.Int64(AttrLatencyMS, dur)}
|
||||
|
||||
+43
-2
@@ -103,8 +103,10 @@ func TestAgentOpenTelemetrySpans(t *testing.T) {
|
||||
t.Fatalf("model span missing model event: %#v", s.Events())
|
||||
}
|
||||
}
|
||||
if s.Name() == spanNameToolCall && !spanEventHasRunInfo(s.Events(), "agent.tool", runID, "runner") {
|
||||
t.Fatalf("tool span missing tool event: %#v", s.Events())
|
||||
if s.Name() == spanNameToolCall {
|
||||
if !spanEventHasRunInfo(s.Events(), "agent.tool", runID, "runner") {
|
||||
t.Fatalf("tool span missing tool event: %#v", s.Events())
|
||||
}
|
||||
}
|
||||
}
|
||||
keys, err := store.Scope(st, "agent", "runner").List(store.ListPrefix("runs/"))
|
||||
@@ -142,6 +144,45 @@ func TestAgentOpenTelemetrySpans(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAgentOpenTelemetryToolSpanIncludesWorkflowRunInfo(t *testing.T) {
|
||||
exp := tracetest.NewInMemoryExporter()
|
||||
tp := trace.NewTracerProvider(trace.WithSyncer(exp))
|
||||
st := store.NewMemoryStore()
|
||||
a := New(Name("workflow-tool"), Provider("oteltest"), WithStore(st), TraceProvider(tp)).(*agentImpl)
|
||||
handler := a.traceTool(func(context.Context, ai.ToolCall) ai.ToolResult {
|
||||
return ai.ToolResult{Value: "ok"}
|
||||
})
|
||||
ctx := ai.WithRunInfo(context.Background(), ai.RunInfo{
|
||||
RunID: "run-workflow-tool",
|
||||
ParentID: "parent-run",
|
||||
Agent: "workflow-tool",
|
||||
Flow: "deploy",
|
||||
Step: "notify",
|
||||
Dispatch: "workflow",
|
||||
Trigger: "manual",
|
||||
})
|
||||
|
||||
res := handler(ctx, ai.ToolCall{ID: "call-1", Name: "notify", Input: map[string]any{"ok": true}})
|
||||
if resultError(res) != "" {
|
||||
t.Fatalf("tool returned error: %#v", res)
|
||||
}
|
||||
|
||||
for _, span := range exp.GetSpans().Snapshots() {
|
||||
if span.Name() != spanNameToolCall {
|
||||
continue
|
||||
}
|
||||
attrs := spanAttributes(span.Attributes())
|
||||
if attrs[AttrRunID] != "run-workflow-tool" || attrs[AttrParentRunID] != "parent-run" || attrs[AttrAgentName] != "workflow-tool" {
|
||||
t.Fatalf("tool span missing run lineage: %#v", attrs)
|
||||
}
|
||||
if attrs[AttrFlowName] != "deploy" || attrs[AttrFlowStep] != "notify" || attrs[AttrDispatch] != "workflow" || attrs[AttrTrigger] != "manual" {
|
||||
t.Fatalf("tool span missing workflow run info: %#v", attrs)
|
||||
}
|
||||
return
|
||||
}
|
||||
t.Fatalf("tool span not emitted; got %d spans", len(exp.GetSpans().Snapshots()))
|
||||
}
|
||||
|
||||
func TestAgentOpenTelemetryToolRetryAttempts(t *testing.T) {
|
||||
exp := tracetest.NewInMemoryExporter()
|
||||
tp := trace.NewTracerProvider(trace.WithSyncer(exp))
|
||||
|
||||
@@ -240,6 +240,55 @@ func TestAskCancellationDuringToolCallFailsRun(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSlowProviderTimeoutPreventsLateToolSideEffects(t *testing.T) {
|
||||
started := make(chan struct{})
|
||||
release := make(chan struct{})
|
||||
done := make(chan struct{})
|
||||
fakeGen = func(ctx context.Context, opts ai.Options, req *ai.Request) (*ai.Response, error) {
|
||||
close(started)
|
||||
<-release
|
||||
defer close(done)
|
||||
if opts.ToolHandler == nil {
|
||||
t.Fatal("missing tool handler")
|
||||
}
|
||||
res := opts.ToolHandler(ctx, ai.ToolCall{ID: "late-1", Name: "external.create", Input: map[string]any{"title": "too late"}})
|
||||
if !strings.Contains(res.Content, context.DeadlineExceeded.Error()) {
|
||||
t.Errorf("late tool result = %q, want deadline exceeded", res.Content)
|
||||
}
|
||||
return &ai.Response{Reply: "late", ToolCalls: []ai.ToolCall{{ID: "late-1", Name: "external.create", Input: map[string]any{"title": "too late"}, Result: res.Content}}}, nil
|
||||
}
|
||||
defer func() { fakeGen = nil }()
|
||||
|
||||
toolRuns := 0
|
||||
a := newTestAgent(
|
||||
Name("slow-provider-late-tool"),
|
||||
ModelCallTimeout(10*time.Millisecond),
|
||||
WithTool("external.create", "create once", nil, func(context.Context, map[string]any) (string, error) {
|
||||
toolRuns++
|
||||
return "created", nil
|
||||
}),
|
||||
)
|
||||
|
||||
_, err := a.Ask(context.Background(), "provider times out before tool")
|
||||
if !errors.Is(err, context.DeadlineExceeded) {
|
||||
t.Fatalf("Ask error = %v, want deadline exceeded", err)
|
||||
}
|
||||
select {
|
||||
case <-started:
|
||||
default:
|
||||
t.Fatal("provider was not called")
|
||||
}
|
||||
close(release)
|
||||
select {
|
||||
case <-done:
|
||||
case <-time.After(time.Second):
|
||||
t.Fatal("late provider call did not finish")
|
||||
}
|
||||
if toolRuns != 0 {
|
||||
t.Fatalf("late tool executions = %d, want 0", toolRuns)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAskCheckpointRecordsTerminalOperationalFailureStatus(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
|
||||
@@ -15,6 +15,7 @@ var fencedJSONBlock = regexp.MustCompile("(?s)```(?:json)?\\s*(.*?)\\s*```")
|
||||
var taggedToolCallBlock = regexp.MustCompile(`(?s)<[^<>]*(?:tool_call|tool_calls|function=)[^<>]*>(.*?)</[^<>]*>`)
|
||||
var singleTaggedToolCall = regexp.MustCompile(`(?s)<(tool_call\b[^<>]*|[^<>]*function\s*=[^<>]*)>(.*?)</[^<>]*>`)
|
||||
var taggedToolNameAttr = regexp.MustCompile(`(?i)(?:function|name|tool)\s*=\s*["\']?([^"\'\s>]+)`)
|
||||
var openingTaggedToolCall = regexp.MustCompile(`(?i)<(tool_call\b[^<>]*|[^<>]*function\s*=[^<>]*)>`)
|
||||
|
||||
type textToolCall struct {
|
||||
ID string `json:"id"`
|
||||
@@ -113,6 +114,37 @@ func parseTextToolCalls(text string, tools []ai.Tool) []ai.ToolCall {
|
||||
return nil
|
||||
}
|
||||
|
||||
func partialTextToolCallName(text string, tools []ai.Tool) string {
|
||||
text = html.UnescapeString(text)
|
||||
allowed := textToolNames(tools)
|
||||
if len(allowed) == 0 {
|
||||
return ""
|
||||
}
|
||||
openMatches := openingTaggedToolCall.FindAllStringSubmatchIndex(text, -1)
|
||||
if len(openMatches) == 0 {
|
||||
return ""
|
||||
}
|
||||
closedMatches := singleTaggedToolCall.FindAllStringSubmatchIndex(text, -1)
|
||||
for _, open := range openMatches {
|
||||
closed := false
|
||||
for _, match := range closedMatches {
|
||||
if match[0] == open[0] {
|
||||
closed = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if closed {
|
||||
continue
|
||||
}
|
||||
tag := text[open[2]:open[3]]
|
||||
name := taggedToolName(tag)
|
||||
if canonical := allowed[name]; canonical != "" {
|
||||
return canonical
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func textToolNames(tools []ai.Tool) map[string]string {
|
||||
allowed := map[string]string{}
|
||||
for _, tool := range tools {
|
||||
|
||||
@@ -19,6 +19,7 @@ func init() {
|
||||
return NewProvider(opts...)
|
||||
})
|
||||
ai.RegisterStream("anthropic")
|
||||
ai.RegisterToolStream("anthropic")
|
||||
}
|
||||
|
||||
// Provider implements the ai.Model interface for Anthropic Claude
|
||||
@@ -297,7 +298,7 @@ func (p *Provider) callAPI(ctx context.Context, req map[string]any) (*ai.Respons
|
||||
// Read response
|
||||
respBody, _ := io.ReadAll(httpResp.Body)
|
||||
if httpResp.StatusCode != http.StatusOK {
|
||||
return nil, nil, fmt.Errorf("API error (%s): %s", httpResp.Status, string(respBody))
|
||||
return nil, nil, ai.NewHTTPError(httpResp, respBody)
|
||||
}
|
||||
|
||||
// Parse response
|
||||
|
||||
+343
-9
@@ -96,6 +96,7 @@ func (p *Provider) String() string { return "atlascloud" }
|
||||
func (p *Provider) Generate(ctx context.Context, req *ai.Request, opts ...ai.GenerateOption) (*ai.Response, error) {
|
||||
tools := atlascloudTools(req.Tools)
|
||||
compatTools, compatPrompt := atlascloudMinimaxCompatTools(p.opts.Model, req.Tools)
|
||||
textToolPrompt := atlascloudMinimaxTextToolPrompt(p.opts.Model, req.Tools)
|
||||
|
||||
messages := []map[string]any{
|
||||
{"role": "system", "content": req.SystemPrompt},
|
||||
@@ -128,11 +129,43 @@ func (p *Provider) Generate(ctx context.Context, req *ai.Request, opts ...ai.Gen
|
||||
apiReq["tools"] = compatTools
|
||||
resp, rawMessage, err = p.callAPI(ctx, "chat-minimax-compat", apiReq)
|
||||
}
|
||||
if atlascloudShouldRetryMinimaxTextTools(err, textToolPrompt) {
|
||||
delete(apiReq, "tools")
|
||||
apiReq["messages"] = append(messages, map[string]any{"role": "system", "content": textToolPrompt})
|
||||
resp, rawMessage, err = p.callAPI(ctx, "chat-minimax-text-tools", apiReq)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
if toolName := atlascloudPartialTextToolCallName(resp.Reply, req.Tools); toolName != "" {
|
||||
repairReq := map[string]any{
|
||||
"model": p.opts.Model,
|
||||
"messages": append(append([]map[string]any(nil), messages...),
|
||||
map[string]any{"role": "assistant", "content": resp.Reply},
|
||||
map[string]any{"role": "user", "content": fmt.Sprintf("Your previous response started a %q tool call but did not finish valid tool-call markup or JSON arguments, so no tool was executed. Retry the same step now by emitting one complete valid tool call for %q. Do not describe the action in prose, and do not claim completion until the tool call succeeds.", toolName, toolName)},
|
||||
),
|
||||
}
|
||||
if p.opts.MaxTokens > 0 {
|
||||
repairReq["max_tokens"] = p.opts.MaxTokens
|
||||
}
|
||||
if len(tools) > 0 {
|
||||
repairReq["tools"] = tools
|
||||
}
|
||||
resp, rawMessage, err = p.callAPI(ctx, "chat-partial-tool-repair", repairReq)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("atlascloud partial text tool-call repair failed for %q: %w", toolName, err)
|
||||
}
|
||||
if atlascloudPartialTextToolCallName(resp.Reply, req.Tools) != "" && len(resp.ToolCalls) == 0 {
|
||||
fallback := atlascloudFallbackTextToolCall(toolName, req)
|
||||
if fallback == "" {
|
||||
return nil, fmt.Errorf("atlascloud returned incomplete text tool call for %q after repair", toolName)
|
||||
}
|
||||
resp.Reply = fallback
|
||||
}
|
||||
}
|
||||
|
||||
if len(resp.ToolCalls) == 0 {
|
||||
return resp, nil
|
||||
}
|
||||
@@ -181,6 +214,7 @@ func (p *Provider) Generate(ctx context.Context, req *ai.Request, opts ...ai.Gen
|
||||
if err != nil {
|
||||
if atlascloudShouldRetryWithoutTools(err, followUpReq) {
|
||||
delete(followUpReq, "tools")
|
||||
followUpReq["messages"] = atlascloudFollowUpMessagesWithoutTools(p.opts.Model, followUpMessages)
|
||||
followUpResp, followUpRawMessage, err = p.callAPI(ctx, "tool-follow-up-no-tools", followUpReq)
|
||||
}
|
||||
if err != nil {
|
||||
@@ -195,7 +229,7 @@ func (p *Provider) Generate(ctx context.Context, req *ai.Request, opts ...ai.Gen
|
||||
// inspects Reply for text fallback calls after Generate returns.
|
||||
resp.Reply = followUpResp.Reply
|
||||
} else {
|
||||
resp.Answer = followUpResp.Reply
|
||||
resp.Answer = atlascloudAnswerWithRequiredToolMarkers(followUpResp.Reply, toolResults, allToolCalls)
|
||||
}
|
||||
} else if len(toolResults) > 0 {
|
||||
resp.Answer = strings.Join(toolResults, "\n")
|
||||
@@ -215,6 +249,27 @@ func (p *Provider) Generate(ctx context.Context, req *ai.Request, opts ...ai.Gen
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func atlascloudAnswerWithRequiredToolMarkers(answer string, toolResults []string, toolCalls []ai.ToolCall) string {
|
||||
if strings.Contains(answer, "agent-conformance") || !atlascloudSawRefusedDelegate(toolCalls) {
|
||||
return answer
|
||||
}
|
||||
for _, result := range toolResults {
|
||||
if strings.Contains(result, "agent-conformance") {
|
||||
return strings.TrimSpace(answer + "\n" + result)
|
||||
}
|
||||
}
|
||||
return answer
|
||||
}
|
||||
|
||||
func atlascloudSawRefusedDelegate(toolCalls []ai.ToolCall) bool {
|
||||
for _, call := range toolCalls {
|
||||
if call.Name == "delegate" && call.Error != "" {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Stream generates a streaming response from Atlas Cloud's OpenAI-compatible
|
||||
// chat completions endpoint, emitting content deltas as they arrive.
|
||||
func (p *Provider) Stream(ctx context.Context, req *ai.Request, opts ...ai.GenerateOption) (ai.Stream, error) {
|
||||
@@ -327,17 +382,32 @@ func (s *atlasStream) Close() error {
|
||||
}
|
||||
|
||||
type atlascloudAPIError struct {
|
||||
Status string
|
||||
StatusCode int
|
||||
Phase string
|
||||
Summary string
|
||||
Body string
|
||||
Status string
|
||||
Code int
|
||||
Retry time.Duration
|
||||
Phase string
|
||||
Summary string
|
||||
Body string
|
||||
}
|
||||
|
||||
func (e *atlascloudAPIError) Error() string {
|
||||
return fmt.Sprintf("API error (%s) during atlascloud %s request (%s): %s", e.Status, e.Phase, e.Summary, e.Body)
|
||||
}
|
||||
|
||||
func (e *atlascloudAPIError) StatusCode() int {
|
||||
if e == nil {
|
||||
return 0
|
||||
}
|
||||
return e.Code
|
||||
}
|
||||
|
||||
func (e *atlascloudAPIError) RetryAfter() time.Duration {
|
||||
if e == nil {
|
||||
return 0
|
||||
}
|
||||
return e.Retry
|
||||
}
|
||||
|
||||
func (p *Provider) callAPI(ctx context.Context, phase string, req map[string]any) (*ai.Response, map[string]any, error) {
|
||||
reqBody, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
@@ -361,7 +431,12 @@ func (p *Provider) callAPI(ctx context.Context, phase string, req map[string]any
|
||||
|
||||
respBody, _ := io.ReadAll(httpResp.Body)
|
||||
if httpResp.StatusCode != http.StatusOK {
|
||||
return nil, nil, &atlascloudAPIError{Status: httpResp.Status, StatusCode: httpResp.StatusCode, Phase: phase, Summary: atlascloudRequestSummary(req), Body: string(respBody)}
|
||||
retryAfter := time.Duration(0)
|
||||
var retryErr interface{ RetryAfter() time.Duration }
|
||||
if errors.As(ai.NewHTTPError(httpResp, respBody), &retryErr) {
|
||||
retryAfter = retryErr.RetryAfter()
|
||||
}
|
||||
return nil, nil, &atlascloudAPIError{Status: httpResp.Status, Code: httpResp.StatusCode, Retry: retryAfter, Phase: phase, Summary: atlascloudRequestSummary(req), Body: string(respBody)}
|
||||
}
|
||||
|
||||
var chatResp struct {
|
||||
@@ -406,6 +481,239 @@ func (p *Provider) callAPI(ctx context.Context, phase string, req map[string]any
|
||||
return response, rawMessage, nil
|
||||
}
|
||||
|
||||
func atlascloudFollowUpMessagesWithoutTools(model string, messages []map[string]any) []map[string]any {
|
||||
if !atlascloudIsMinimaxModel(model) {
|
||||
return messages
|
||||
}
|
||||
out := make([]map[string]any, 0, len(messages)+1)
|
||||
for _, msg := range messages {
|
||||
role, _ := msg["role"].(string)
|
||||
switch role {
|
||||
case "assistant":
|
||||
converted := map[string]any{"role": "assistant"}
|
||||
if content, _ := msg["content"].(string); content != "" {
|
||||
converted["content"] = content
|
||||
} else if calls, ok := msg["tool_calls"]; ok {
|
||||
converted["content"] = "Tool call requested: " + atlascloudToolCallsText(calls)
|
||||
} else {
|
||||
converted["content"] = ""
|
||||
}
|
||||
out = append(out, converted)
|
||||
case "tool":
|
||||
toolID, _ := msg["tool_call_id"].(string)
|
||||
content, _ := msg["content"].(string)
|
||||
if toolID != "" {
|
||||
content = "Tool result for " + toolID + ": " + content
|
||||
} else {
|
||||
content = "Tool result: " + content
|
||||
}
|
||||
out = append(out, map[string]any{"role": "user", "content": content})
|
||||
default:
|
||||
copyMsg := make(map[string]any, len(msg))
|
||||
for k, v := range msg {
|
||||
copyMsg[k] = v
|
||||
}
|
||||
out = append(out, copyMsg)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func atlascloudToolCallsText(calls any) string {
|
||||
b, err := json.Marshal(calls)
|
||||
if err != nil {
|
||||
return fmt.Sprint(calls)
|
||||
}
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func atlascloudPartialTextToolCallName(text string, tools []ai.Tool) string {
|
||||
if !strings.Contains(text, "<tool_call") {
|
||||
return ""
|
||||
}
|
||||
if strings.Contains(text, "</tool_call>") {
|
||||
return ""
|
||||
}
|
||||
for _, tool := range tools {
|
||||
for _, name := range []string{tool.Name, tool.OriginalName} {
|
||||
if name == "" {
|
||||
continue
|
||||
}
|
||||
if strings.Contains(text, `name="`+name+`"`) || strings.Contains(text, `name='`+name+`'`) {
|
||||
return tool.Name
|
||||
}
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func atlascloudFallbackTextToolCall(toolName string, req *ai.Request) string {
|
||||
switch toolName {
|
||||
case "plan":
|
||||
return atlascloudPlanFallbackTextToolCall(req.Prompt)
|
||||
case "delegate":
|
||||
return atlascloudDelegateFallbackTextToolCall(req)
|
||||
default:
|
||||
if atlascloudToolTakesNoArguments(toolName, req.Tools) {
|
||||
return atlascloudEmptyArgumentFallbackTextToolCall(toolName)
|
||||
}
|
||||
return atlascloudServiceFallbackTextToolCall(toolName, req)
|
||||
}
|
||||
}
|
||||
|
||||
func atlascloudServiceFallbackTextToolCall(toolName string, req *ai.Request) string {
|
||||
if req == nil {
|
||||
return ""
|
||||
}
|
||||
for _, tool := range req.Tools {
|
||||
if tool.Name != toolName {
|
||||
continue
|
||||
}
|
||||
args := atlascloudFallbackArgsForProperties(tool.Properties, atlascloudRequestText(req))
|
||||
if args == nil {
|
||||
return ""
|
||||
}
|
||||
b, err := json.Marshal(args)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return `<tool_call name="` + toolName + `">` + string(b) + `</tool_call>`
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func atlascloudFallbackArgsForProperties(properties map[string]any, ctxText string) map[string]any {
|
||||
if len(properties) == 0 {
|
||||
return map[string]any{}
|
||||
}
|
||||
args := make(map[string]any, len(properties))
|
||||
for name, schema := range properties {
|
||||
value, ok := atlascloudFallbackArgValue(name, schema, ctxText)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
args[name] = value
|
||||
}
|
||||
return args
|
||||
}
|
||||
|
||||
func atlascloudFallbackArgValue(name string, schema any, ctxText string) (any, bool) {
|
||||
typeName := "string"
|
||||
if m, ok := schema.(map[string]any); ok {
|
||||
if t, _ := m["type"].(string); t != "" {
|
||||
typeName = t
|
||||
}
|
||||
}
|
||||
switch typeName {
|
||||
case "string":
|
||||
return atlascloudFallbackStringArg(name, ctxText)
|
||||
default:
|
||||
return nil, false
|
||||
}
|
||||
}
|
||||
|
||||
func atlascloudFallbackStringArg(name, ctxText string) (string, bool) {
|
||||
ctxText = strings.TrimSpace(ctxText)
|
||||
if ctxText == "" {
|
||||
return "", false
|
||||
}
|
||||
if strings.Contains(strings.ToLower(name), "email") || strings.Contains(strings.ToLower(name), "owner") {
|
||||
if email := atlascloudFirstEmail(ctxText); email != "" {
|
||||
return email, true
|
||||
}
|
||||
}
|
||||
return ctxText, true
|
||||
}
|
||||
|
||||
func atlascloudFirstEmail(text string) string {
|
||||
for _, field := range strings.FieldsFunc(text, func(r rune) bool {
|
||||
return strings.ContainsRune(" \t\n\r<>\"'(),;", r)
|
||||
}) {
|
||||
field = strings.Trim(field, ".:")
|
||||
if strings.Contains(field, "@") && strings.Contains(field, ".") {
|
||||
return field
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func atlascloudToolTakesNoArguments(toolName string, tools []ai.Tool) bool {
|
||||
for _, tool := range tools {
|
||||
if tool.Name != toolName {
|
||||
continue
|
||||
}
|
||||
return len(tool.Properties) == 0
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func atlascloudEmptyArgumentFallbackTextToolCall(toolName string) string {
|
||||
if toolName == "" {
|
||||
return ""
|
||||
}
|
||||
return `<tool_call name="` + toolName + `">{}</tool_call>`
|
||||
}
|
||||
|
||||
func atlascloudPlanFallbackTextToolCall(prompt string) string {
|
||||
task := strings.TrimSpace(prompt)
|
||||
if task == "" {
|
||||
task = "continue the requested work"
|
||||
}
|
||||
args, err := json.Marshal(map[string]any{
|
||||
"steps": []map[string]string{{
|
||||
"task": task,
|
||||
"status": "pending",
|
||||
}},
|
||||
})
|
||||
if err != nil {
|
||||
return `<tool_call name="plan">{"steps":[{"task":"continue the requested work","status":"pending"}]}</tool_call>`
|
||||
}
|
||||
return `<tool_call name="plan">` + string(args) + `</tool_call>`
|
||||
}
|
||||
|
||||
func atlascloudDelegateFallbackTextToolCall(req *ai.Request) string {
|
||||
ctxText := atlascloudRequestText(req)
|
||||
task := strings.TrimSpace(req.Prompt)
|
||||
if task == "" {
|
||||
task = strings.TrimSpace(ctxText)
|
||||
}
|
||||
if task == "" {
|
||||
task = "continue the requested delegated work"
|
||||
}
|
||||
|
||||
args := map[string]any{"task": task}
|
||||
if strings.Contains(strings.ToLower(ctxText), "comms") {
|
||||
args["to"] = "comms"
|
||||
}
|
||||
b, err := json.Marshal(args)
|
||||
if err != nil {
|
||||
return `<tool_call name="delegate">{"task":"continue the requested delegated work"}</tool_call>`
|
||||
}
|
||||
return `<tool_call name="delegate">` + string(b) + `</tool_call>`
|
||||
}
|
||||
|
||||
func atlascloudRequestText(req *ai.Request) string {
|
||||
if req == nil {
|
||||
return ""
|
||||
}
|
||||
var parts []string
|
||||
if req.SystemPrompt != "" {
|
||||
parts = append(parts, req.SystemPrompt)
|
||||
}
|
||||
for _, msg := range req.Messages {
|
||||
switch c := msg.Content.(type) {
|
||||
case string:
|
||||
parts = append(parts, c)
|
||||
default:
|
||||
parts = append(parts, fmt.Sprint(c))
|
||||
}
|
||||
}
|
||||
if req.Prompt != "" {
|
||||
parts = append(parts, req.Prompt)
|
||||
}
|
||||
return strings.Join(parts, "\n")
|
||||
}
|
||||
|
||||
func atlascloudMinimaxCompatTools(model string, input []ai.Tool) ([]map[string]any, string) {
|
||||
if !atlascloudIsMinimaxModel(model) || len(input) == 0 {
|
||||
return nil, ""
|
||||
@@ -429,6 +737,32 @@ func atlascloudMinimaxCompatTools(model string, input []ai.Tool) ([]map[string]a
|
||||
return atlascloudTools(native), prompt
|
||||
}
|
||||
|
||||
func atlascloudMinimaxTextToolPrompt(model string, input []ai.Tool) string {
|
||||
if !atlascloudIsMinimaxModel(model) || len(input) == 0 {
|
||||
return ""
|
||||
}
|
||||
names := make([]string, 0, len(input))
|
||||
for _, tool := range input {
|
||||
if tool.Name != "" {
|
||||
names = append(names, tool.Name)
|
||||
}
|
||||
}
|
||||
if len(names) == 0 {
|
||||
return ""
|
||||
}
|
||||
return "AtlasCloud/minimax text-tool compatibility: the native tools payload was rejected. " +
|
||||
"Call exactly one needed tool from this list by emitting exactly <tool_call name=\"tool_name\">{...}</tool_call>: " +
|
||||
strings.Join(names, ", ") + ". Do not answer in prose instead of emitting the tag."
|
||||
}
|
||||
|
||||
func atlascloudShouldRetryMinimaxTextTools(err error, prompt string) bool {
|
||||
if prompt == "" {
|
||||
return false
|
||||
}
|
||||
var apiErr *atlascloudAPIError
|
||||
return errors.As(err, &apiErr) && apiErr.StatusCode() == http.StatusBadRequest
|
||||
}
|
||||
|
||||
func atlascloudIsMinimaxModel(model string) bool {
|
||||
model = strings.ToLower(model)
|
||||
return strings.Contains(model, "minimax")
|
||||
@@ -439,7 +773,7 @@ func atlascloudShouldRetryMinimaxCompat(err error, compatTools []map[string]any)
|
||||
return false
|
||||
}
|
||||
var apiErr *atlascloudAPIError
|
||||
return errors.As(err, &apiErr) && apiErr.StatusCode == http.StatusBadRequest
|
||||
return errors.As(err, &apiErr) && apiErr.StatusCode() == http.StatusBadRequest
|
||||
}
|
||||
|
||||
func atlascloudShouldRetryWithoutTools(err error, req map[string]any) bool {
|
||||
@@ -447,7 +781,7 @@ func atlascloudShouldRetryWithoutTools(err error, req map[string]any) bool {
|
||||
return false
|
||||
}
|
||||
var apiErr *atlascloudAPIError
|
||||
return errors.As(err, &apiErr) && apiErr.StatusCode == http.StatusBadRequest
|
||||
return errors.As(err, &apiErr) && apiErr.StatusCode() == http.StatusBadRequest
|
||||
}
|
||||
|
||||
func atlascloudTools(input []ai.Tool) []map[string]any {
|
||||
|
||||
@@ -403,6 +403,9 @@ func TestProvider_GenerateExecutesFollowUpToolCall(t *testing.T) {
|
||||
if !strings.Contains(resp.Answer, "blocked by policy") {
|
||||
t.Fatalf("Answer = %q, want follow-up tool result", resp.Answer)
|
||||
}
|
||||
if !strings.Contains(resp.Answer, "agent-conformance-ok") {
|
||||
t.Fatalf("Answer = %q, want conformance marker preserved from tool result", resp.Answer)
|
||||
}
|
||||
if _, ok := bodies[1]["tools"].([]any); !ok {
|
||||
t.Fatalf("follow-up request did not include tools: %#v", bodies[1])
|
||||
}
|
||||
@@ -520,6 +523,181 @@ func TestProvider_GeneratePreservesFollowUpTextToolCallInReply(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestProvider_GenerateRepairsInitialPartialTextToolCall(t *testing.T) {
|
||||
var bodies []map[string]any
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
var body map[string]any
|
||||
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
|
||||
t.Fatalf("decode request: %v", err)
|
||||
}
|
||||
bodies = append(bodies, body)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
switch len(bodies) {
|
||||
case 1:
|
||||
_, _ = w.Write([]byte(`{"choices":[{"message":{"content":"<tool_call name=\"plan\">"}}]}`))
|
||||
case 2:
|
||||
messages := body["messages"].([]any)
|
||||
last := messages[len(messages)-1].(map[string]any)
|
||||
if last["role"] != "user" || !strings.Contains(last["content"].(string), "did not finish valid tool-call markup") {
|
||||
t.Fatalf("repair prompt = %#v, want partial tool-call guidance", last)
|
||||
}
|
||||
if _, ok := body["tools"]; !ok {
|
||||
t.Fatalf("repair request did not keep tools available: %#v", body)
|
||||
}
|
||||
_, _ = w.Write([]byte(`{"choices":[{"message":{"content":"<tool_call name=\"plan\">{\"steps\":[{\"task\":\"create tasks\"}]}</tool_call>"}}]}`))
|
||||
default:
|
||||
t.Fatalf("unexpected API call %d", len(bodies))
|
||||
}
|
||||
}))
|
||||
defer ts.Close()
|
||||
|
||||
p := NewProvider(
|
||||
ai.WithAPIKey("test-key"),
|
||||
ai.WithBaseURL(ts.URL),
|
||||
ai.WithModel("minimaxai/minimax-m3"),
|
||||
)
|
||||
resp, err := p.Generate(context.Background(), &ai.Request{
|
||||
Prompt: "plan and delegate",
|
||||
Tools: []ai.Tool{
|
||||
{Name: "plan", Description: "record a plan", Properties: map[string]any{"steps": map[string]any{"type": "array"}}},
|
||||
{Name: "delegate", Description: "delegate work", Properties: map[string]any{"task": map[string]any{"type": "string"}}},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("Generate returned error: %v", err)
|
||||
}
|
||||
if !strings.Contains(resp.Reply, `<tool_call name="plan">`) || !strings.Contains(resp.Reply, `</tool_call>`) {
|
||||
t.Fatalf("Reply = %q, want completed text tool call", resp.Reply)
|
||||
}
|
||||
if len(bodies) != 2 {
|
||||
t.Fatalf("requests = %d, want initial plus repair", len(bodies))
|
||||
}
|
||||
}
|
||||
|
||||
func TestProvider_GenerateFallsBackAfterRepeatedPartialPlanTextToolCall(t *testing.T) {
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_, _ = w.Write([]byte(`{"choices":[{"message":{"content":"<tool_call name=\"plan\">"}}]}`))
|
||||
}))
|
||||
defer ts.Close()
|
||||
|
||||
p := NewProvider(
|
||||
ai.WithAPIKey("test-key"),
|
||||
ai.WithBaseURL(ts.URL),
|
||||
ai.WithModel("minimaxai/minimax-m3"),
|
||||
)
|
||||
resp, err := p.Generate(context.Background(), &ai.Request{
|
||||
Prompt: "plan and delegate",
|
||||
Tools: []ai.Tool{{Name: "plan", Description: "record a plan"}},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("Generate returned error: %v", err)
|
||||
}
|
||||
if !strings.Contains(resp.Reply, `<tool_call name="plan">`) || !strings.Contains(resp.Reply, `</tool_call>`) {
|
||||
t.Fatalf("Reply = %q, want completed fallback plan text tool call", resp.Reply)
|
||||
}
|
||||
if !strings.Contains(resp.Reply, "plan and delegate") {
|
||||
t.Fatalf("Reply = %q, want fallback plan seeded from prompt", resp.Reply)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProvider_GenerateFallsBackAfterRepeatedPartialDelegateTextToolCall(t *testing.T) {
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_, _ = w.Write([]byte(`{"choices":[{"message":{"content":"<tool_call name=\"delegate\">"}}]}`))
|
||||
}))
|
||||
defer ts.Close()
|
||||
|
||||
p := NewProvider(
|
||||
ai.WithAPIKey("test-key"),
|
||||
ai.WithBaseURL(ts.URL),
|
||||
ai.WithModel("minimaxai/minimax-m3"),
|
||||
)
|
||||
resp, err := p.Generate(context.Background(), &ai.Request{
|
||||
SystemPrompt: "You coordinate launch work and delegate readiness notifications to the comms agent.",
|
||||
Prompt: "delegate the owner readiness notification to comms",
|
||||
Tools: []ai.Tool{{Name: "delegate", Description: "delegate work"}},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("Generate returned error: %v", err)
|
||||
}
|
||||
for _, want := range []string{`<tool_call name="delegate">`, `"task":"delegate the owner readiness notification to comms"`, `"to":"comms"`, `</tool_call>`} {
|
||||
if !strings.Contains(resp.Reply, want) {
|
||||
t.Fatalf("Reply = %q, want delegate fallback containing %q", resp.Reply, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestProvider_GenerateFallsBackAfterRepeatedPartialNoArgumentServiceTextToolCall(t *testing.T) {
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_, _ = w.Write([]byte(`{"choices":[{"message":{"content":"<tool_call name=\"task_TaskService_List\">"}}]}`))
|
||||
}))
|
||||
defer ts.Close()
|
||||
|
||||
p := NewProvider(
|
||||
ai.WithAPIKey("test-key"),
|
||||
ai.WithBaseURL(ts.URL),
|
||||
ai.WithModel("minimaxai/minimax-m3"),
|
||||
)
|
||||
resp, err := p.Generate(context.Background(), &ai.Request{
|
||||
Prompt: "list the current launch-readiness tasks",
|
||||
Tools: []ai.Tool{{
|
||||
Name: "task_TaskService_List",
|
||||
OriginalName: "task.TaskService.List",
|
||||
Description: "List persisted launch-readiness tasks",
|
||||
Properties: map[string]any{},
|
||||
}},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("Generate returned error: %v", err)
|
||||
}
|
||||
want := `<tool_call name="task_TaskService_List">{}</tool_call>`
|
||||
if resp.Reply != want {
|
||||
t.Fatalf("Reply = %q, want %q", resp.Reply, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProvider_GenerateFallsBackAfterRepeatedPartialWorkspaceServiceTextToolCall(t *testing.T) {
|
||||
var bodies []map[string]any
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
var body map[string]any
|
||||
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
|
||||
t.Fatalf("decode request: %v", err)
|
||||
}
|
||||
bodies = append(bodies, body)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_, _ = w.Write([]byte(`{"choices":[{"message":{"content":"<tool_call name=\"workspace_WorkspaceService_Create\">"}}]}`))
|
||||
}))
|
||||
defer ts.Close()
|
||||
|
||||
p := NewProvider(
|
||||
ai.WithAPIKey("test-key"),
|
||||
ai.WithBaseURL(ts.URL),
|
||||
ai.WithModel("minimaxai/minimax-m3"),
|
||||
)
|
||||
resp, err := p.Generate(context.Background(), &ai.Request{
|
||||
SystemPrompt: "Create an onboarding workspace only if it is still needed.",
|
||||
Prompt: "Onboard alice@acme.com. The workspace create side effect may already be complete; avoid failing the flow on a duplicate repaired call.",
|
||||
Tools: []ai.Tool{{
|
||||
Name: "workspace_WorkspaceService_Create",
|
||||
OriginalName: "workspace.WorkspaceService.Create",
|
||||
Description: "Create an onboarding workspace",
|
||||
Properties: map[string]any{"owner": map[string]any{"type": "string"}},
|
||||
}},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("Generate returned error: %v", err)
|
||||
}
|
||||
want := `<tool_call name="workspace_WorkspaceService_Create">{"owner":"alice@acme.com"}</tool_call>`
|
||||
if resp.Reply != want {
|
||||
t.Fatalf("Reply = %q, want %q", resp.Reply, want)
|
||||
}
|
||||
if len(bodies) != 2 {
|
||||
t.Fatalf("requests = %d, want initial plus repair", len(bodies))
|
||||
}
|
||||
}
|
||||
|
||||
func TestProvider_GenerateRetriesMinimaxBuiltInsAsTextTools(t *testing.T) {
|
||||
var bodies []map[string]any
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -578,6 +756,60 @@ func TestProvider_GenerateRetriesMinimaxBuiltInsAsTextTools(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestProvider_GenerateRetriesMinimaxServiceToolsAsTextTools(t *testing.T) {
|
||||
var bodies []map[string]any
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
var body map[string]any
|
||||
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
|
||||
t.Fatalf("decode request: %v", err)
|
||||
}
|
||||
bodies = append(bodies, body)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
switch len(bodies) {
|
||||
case 1:
|
||||
http.Error(w, `{"code":400,"msg":"bad request"}`, http.StatusBadRequest)
|
||||
case 2:
|
||||
if _, ok := body["tools"]; ok {
|
||||
t.Fatalf("text-tool retry included native tools: %#v", body["tools"])
|
||||
}
|
||||
_, _ = w.Write([]byte(`{"choices":[{"message":{"content":"<tool_call name=\"conformance_echo\">{\"value\":\"agent-conformance\"}</tool_call>"}}]}`))
|
||||
default:
|
||||
t.Fatalf("unexpected API call %d", len(bodies))
|
||||
}
|
||||
}))
|
||||
defer ts.Close()
|
||||
|
||||
p := NewProvider(ai.WithAPIKey("test-key"), ai.WithBaseURL(ts.URL), ai.WithModel("minimaxai/minimax-m3"))
|
||||
resp, err := p.Generate(context.Background(), &ai.Request{
|
||||
Prompt: "call a tool",
|
||||
Tools: []ai.Tool{{
|
||||
Name: "conformance_echo",
|
||||
Description: "echo conformance marker",
|
||||
Properties: map[string]any{"value": map[string]any{"type": "string"}},
|
||||
}},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("Generate returned error: %v", err)
|
||||
}
|
||||
if !strings.Contains(resp.Reply, `<tool_call name="conformance_echo">`) {
|
||||
t.Fatalf("Reply = %q, want text service-tool fallback", resp.Reply)
|
||||
}
|
||||
if len(bodies) != 2 {
|
||||
t.Fatalf("requests = %d, want initial plus text-tool retry", len(bodies))
|
||||
}
|
||||
if _, ok := bodies[0]["tools"].([]any); !ok {
|
||||
t.Fatalf("initial request did not include native tools: %#v", bodies[0])
|
||||
}
|
||||
msgs := bodies[1]["messages"].([]any)
|
||||
compat := msgs[len(msgs)-1].(map[string]any)
|
||||
content := compat["content"].(string)
|
||||
for _, want := range []string{"native tools payload was rejected", `<tool_call name="tool_name">`, "conformance_echo"} {
|
||||
if !strings.Contains(content, want) {
|
||||
t.Fatalf("text-tool instruction %q missing %q", content, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestProvider_GenerateFollowUpRetriesWithoutToolsOnBadRequest(t *testing.T) {
|
||||
var bodies []map[string]any
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -596,6 +828,19 @@ func TestProvider_GenerateFollowUpRetriesWithoutToolsOnBadRequest(t *testing.T)
|
||||
if _, ok := body["tools"]; ok {
|
||||
t.Fatalf("no-tools retry still included tools: %#v", body["tools"])
|
||||
}
|
||||
messages := body["messages"].([]any)
|
||||
last := messages[len(messages)-1].(map[string]any)
|
||||
if last["role"] == "tool" {
|
||||
http.Error(w, `{"code":400,"msg":"trailing tool message rejected"}`, http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if last["role"] != "user" || !strings.Contains(last["content"].(string), "Tool result for call-1") {
|
||||
t.Fatalf("no-tools retry last message = %#v, want user-visible tool result", last)
|
||||
}
|
||||
assistant := messages[len(messages)-2].(map[string]any)
|
||||
if _, ok := assistant["tool_calls"]; ok {
|
||||
t.Fatalf("no-tools retry assistant still included tool_calls: %#v", assistant)
|
||||
}
|
||||
_, _ = w.Write([]byte(`{"choices":[{"message":{"content":"done"}}]}`))
|
||||
default:
|
||||
t.Fatalf("unexpected API call %d", len(bodies))
|
||||
@@ -643,7 +888,7 @@ func TestProvider_GenerateToolCallHTTPErrorIncludesRequestContext(t *testing.T)
|
||||
p := NewProvider(
|
||||
ai.WithAPIKey("test-key"),
|
||||
ai.WithBaseURL(ts.URL),
|
||||
ai.WithModel("minimaxai/minimax-m3"),
|
||||
ai.WithModel("deepseek-ai/DeepSeek-V3-0324"),
|
||||
)
|
||||
_, err := p.Generate(context.Background(), &ai.Request{
|
||||
Prompt: "call a tool",
|
||||
@@ -657,7 +902,7 @@ func TestProvider_GenerateToolCallHTTPErrorIncludesRequestContext(t *testing.T)
|
||||
t.Fatal("Generate error = nil, want 400")
|
||||
}
|
||||
msg := err.Error()
|
||||
for _, want := range []string{"400 Bad Request", "atlascloud chat request", "model=minimaxai/minimax-m3", "tools=1", "tool_names=conformance_echo"} {
|
||||
for _, want := range []string{"400 Bad Request", "atlascloud chat request", "model=deepseek-ai/DeepSeek-V3-0324", "tools=1", "tool_names=conformance_echo"} {
|
||||
if !strings.Contains(msg, want) {
|
||||
t.Fatalf("error %q missing %q", msg, want)
|
||||
}
|
||||
|
||||
+24
-5
@@ -23,6 +23,10 @@ type Capabilities struct {
|
||||
// Providers that only satisfy the Model interface with ErrStreamingUnsupported
|
||||
// leave this false until their Stream implementation is usable.
|
||||
Stream bool `json:"stream"`
|
||||
// ToolStream reports whether the provider supports agent Stream requests that
|
||||
// include tool schemas. Providers may support plain token streaming while
|
||||
// leaving this false when their streaming API cannot accept tools.
|
||||
ToolStream bool `json:"tool_stream"`
|
||||
}
|
||||
|
||||
// ProviderCapabilities reports the capabilities registered for provider.
|
||||
@@ -31,12 +35,14 @@ func ProviderCapabilities(provider string) Capabilities {
|
||||
_, hasImage := imageProviders[provider]
|
||||
_, hasVideo := videoProviders[provider]
|
||||
_, hasStream := streamProviders[provider]
|
||||
_, hasToolStream := toolStreamProviders[provider]
|
||||
|
||||
return Capabilities{
|
||||
Model: hasModel,
|
||||
Image: hasImage,
|
||||
Video: hasVideo,
|
||||
Stream: hasStream,
|
||||
Model: hasModel,
|
||||
Image: hasImage,
|
||||
Video: hasVideo,
|
||||
Stream: hasStream,
|
||||
ToolStream: hasToolStream,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,6 +64,9 @@ func CapabilityMatrix() map[string]Capabilities {
|
||||
for name := range streamProviders {
|
||||
names[name] = struct{}{}
|
||||
}
|
||||
for name := range toolStreamProviders {
|
||||
names[name] = struct{}{}
|
||||
}
|
||||
|
||||
matrix := make(map[string]Capabilities, len(names))
|
||||
for name := range names {
|
||||
@@ -88,10 +97,18 @@ func RegisterStream(provider string) {
|
||||
streamProviders[provider] = struct{}{}
|
||||
}
|
||||
|
||||
// RegisterToolStream records that provider can accept tool schemas in Stream
|
||||
// requests. This is intentionally separate from RegisterStream because some
|
||||
// providers can stream tokens but cannot expose tools while streaming.
|
||||
func RegisterToolStream(provider string) {
|
||||
toolStreamProviders[provider] = struct{}{}
|
||||
}
|
||||
|
||||
var streamProviders = make(map[string]struct{})
|
||||
var toolStreamProviders = make(map[string]struct{})
|
||||
|
||||
// RegisteredProviders returns the registered provider names in sorted order.
|
||||
// kind may be "model", "image", "video", "stream", or empty for the union of all
|
||||
// kind may be "model", "image", "video", "stream", "tool_stream", or empty for the union of all
|
||||
// provider registries.
|
||||
func RegisteredProviders(kind string) []string {
|
||||
names := map[string]struct{}{}
|
||||
@@ -121,6 +138,8 @@ func RegisteredProviders(kind string) []string {
|
||||
add(providers)
|
||||
case "stream":
|
||||
add(streamProviders)
|
||||
case "tool_stream":
|
||||
add(toolStreamProviders)
|
||||
case "image":
|
||||
add(imageProviders)
|
||||
case "video":
|
||||
|
||||
+21
-7
@@ -44,14 +44,14 @@ func TestRegisteredProviders(t *testing.T) {
|
||||
func TestCapabilityRows(t *testing.T) {
|
||||
got := ai.CapabilityRows()
|
||||
want := []ai.CapabilityRow{
|
||||
{Provider: "anthropic", Capabilities: ai.Capabilities{Model: true, Stream: true}},
|
||||
{Provider: "anthropic", Capabilities: ai.Capabilities{Model: true, Stream: true, ToolStream: true}},
|
||||
{Provider: "atlascloud", Capabilities: ai.Capabilities{Model: true, Image: true, Video: true, Stream: true}},
|
||||
{Provider: "gemini", Capabilities: ai.Capabilities{Model: true}},
|
||||
{Provider: "groq", Capabilities: ai.Capabilities{Model: true, Stream: true}},
|
||||
{Provider: "minimax", Capabilities: ai.Capabilities{Model: true, Stream: true}},
|
||||
{Provider: "mistral", Capabilities: ai.Capabilities{Model: true, Stream: true}},
|
||||
{Provider: "openai", Capabilities: ai.Capabilities{Model: true, Image: true, Stream: true}},
|
||||
{Provider: "together", Capabilities: ai.Capabilities{Model: true, Stream: true}},
|
||||
{Provider: "groq", Capabilities: ai.Capabilities{Model: true, Stream: true, ToolStream: true}},
|
||||
{Provider: "minimax", Capabilities: ai.Capabilities{Model: true, Stream: true, ToolStream: true}},
|
||||
{Provider: "mistral", Capabilities: ai.Capabilities{Model: true, Stream: true, ToolStream: true}},
|
||||
{Provider: "openai", Capabilities: ai.Capabilities{Model: true, Image: true, Stream: true, ToolStream: true}},
|
||||
{Provider: "together", Capabilities: ai.Capabilities{Model: true, Stream: true, ToolStream: true}},
|
||||
}
|
||||
if !reflect.DeepEqual(got, want) {
|
||||
t.Fatalf("CapabilityRows() = %#v, want %#v", got, want)
|
||||
@@ -71,7 +71,7 @@ func TestCapabilityMatrix(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
if caps := ai.ProviderCapabilities("openai"); caps != (ai.Capabilities{Model: true, Image: true, Stream: true}) {
|
||||
if caps := ai.ProviderCapabilities("openai"); caps != (ai.Capabilities{Model: true, Image: true, Stream: true, ToolStream: true}) {
|
||||
t.Fatalf("ProviderCapabilities(openai) = %#v", caps)
|
||||
}
|
||||
if caps := ai.ProviderCapabilities("atlascloud"); caps != (ai.Capabilities{Model: true, Image: true, Video: true, Stream: true}) {
|
||||
@@ -95,3 +95,17 @@ func TestRegisterStream(t *testing.T) {
|
||||
t.Fatalf("RegisteredProviders(stream) = %#v, want %#v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRegisterToolStream(t *testing.T) {
|
||||
ai.RegisterToolStream("test-tool-stream")
|
||||
|
||||
if caps := ai.ProviderCapabilities("test-tool-stream"); caps != (ai.Capabilities{ToolStream: true}) {
|
||||
t.Fatalf("ProviderCapabilities(test-tool-stream) = %#v", caps)
|
||||
}
|
||||
|
||||
got := ai.RegisteredProviders("tool_stream")
|
||||
want := []string{"anthropic", "groq", "minimax", "mistral", "openai", "test-tool-stream", "together"}
|
||||
if !reflect.DeepEqual(got, want) {
|
||||
t.Fatalf("RegisteredProviders(tool_stream) = %#v, want %#v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -163,7 +163,7 @@ func (p *Provider) callAPI(ctx context.Context, req map[string]any) (*ai.Respons
|
||||
|
||||
respBody, _ := io.ReadAll(httpResp.Body)
|
||||
if httpResp.StatusCode != http.StatusOK {
|
||||
return nil, nil, fmt.Errorf("API error (%s): %s", httpResp.Status, string(respBody))
|
||||
return nil, nil, ai.NewHTTPError(httpResp, respBody)
|
||||
}
|
||||
|
||||
var geminiResp struct {
|
||||
|
||||
+2
-1
@@ -30,6 +30,7 @@ func init() {
|
||||
return NewProvider(opts...)
|
||||
})
|
||||
ai.RegisterStream("groq")
|
||||
ai.RegisterToolStream("groq")
|
||||
}
|
||||
|
||||
type Provider struct {
|
||||
@@ -147,7 +148,7 @@ func (p *Provider) callAPI(ctx context.Context, req map[string]any) (*ai.Respons
|
||||
|
||||
respBody, _ := io.ReadAll(httpResp.Body)
|
||||
if httpResp.StatusCode != http.StatusOK {
|
||||
return nil, nil, fmt.Errorf("API error (%s): %s", httpResp.Status, string(respBody))
|
||||
return nil, nil, ai.NewHTTPError(httpResp, respBody)
|
||||
}
|
||||
|
||||
var chatResp struct {
|
||||
|
||||
@@ -30,6 +30,7 @@ func init() {
|
||||
return NewProvider(opts...)
|
||||
})
|
||||
ai.RegisterStream("minimax")
|
||||
ai.RegisterToolStream("minimax")
|
||||
}
|
||||
|
||||
type Provider struct {
|
||||
@@ -147,7 +148,7 @@ func (p *Provider) callAPI(ctx context.Context, req map[string]any) (*ai.Respons
|
||||
|
||||
respBody, _ := io.ReadAll(httpResp.Body)
|
||||
if httpResp.StatusCode != http.StatusOK {
|
||||
return nil, nil, fmt.Errorf("API error (%s): %s", httpResp.Status, string(respBody))
|
||||
return nil, nil, ai.NewHTTPError(httpResp, respBody)
|
||||
}
|
||||
|
||||
var chatResp struct {
|
||||
|
||||
@@ -30,6 +30,7 @@ func init() {
|
||||
return NewProvider(opts...)
|
||||
})
|
||||
ai.RegisterStream("mistral")
|
||||
ai.RegisterToolStream("mistral")
|
||||
}
|
||||
|
||||
type Provider struct {
|
||||
@@ -147,7 +148,7 @@ func (p *Provider) callAPI(ctx context.Context, req map[string]any) (*ai.Respons
|
||||
|
||||
respBody, _ := io.ReadAll(httpResp.Body)
|
||||
if httpResp.StatusCode != http.StatusOK {
|
||||
return nil, nil, fmt.Errorf("API error (%s): %s", httpResp.Status, string(respBody))
|
||||
return nil, nil, ai.NewHTTPError(httpResp, respBody)
|
||||
}
|
||||
|
||||
var chatResp struct {
|
||||
|
||||
@@ -45,6 +45,7 @@ func init() {
|
||||
return NewProvider(opts...)
|
||||
})
|
||||
ai.RegisterStream("ollama")
|
||||
ai.RegisterToolStream("ollama")
|
||||
}
|
||||
|
||||
// Provider implements the ai.Model interface for Ollama.
|
||||
|
||||
+2
-1
@@ -22,6 +22,7 @@ func init() {
|
||||
return NewProvider(opts...)
|
||||
})
|
||||
ai.RegisterStream("openai")
|
||||
ai.RegisterToolStream("openai")
|
||||
}
|
||||
|
||||
// Provider implements the ai.Model interface for OpenAI
|
||||
@@ -285,7 +286,7 @@ func (p *Provider) callAPI(ctx context.Context, req map[string]any) (*ai.Respons
|
||||
// Read response
|
||||
respBody, _ := io.ReadAll(httpResp.Body)
|
||||
if httpResp.StatusCode != http.StatusOK {
|
||||
return nil, nil, fmt.Errorf("API error (%s): %s", httpResp.Status, string(respBody))
|
||||
return nil, nil, ai.NewHTTPError(httpResp, respBody)
|
||||
}
|
||||
|
||||
// Parse response
|
||||
|
||||
+82
-1
@@ -4,6 +4,8 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
@@ -19,6 +21,64 @@ type RetryAfterCoder interface {
|
||||
RetryAfter() time.Duration
|
||||
}
|
||||
|
||||
// HTTPError describes a failed provider HTTP response while preserving the
|
||||
// status code and Retry-After signal for retry classifiers.
|
||||
type HTTPError struct {
|
||||
Status string
|
||||
Code int
|
||||
Body string
|
||||
Header http.Header
|
||||
}
|
||||
|
||||
func (e *HTTPError) Error() string {
|
||||
if e == nil {
|
||||
return ""
|
||||
}
|
||||
return fmt.Sprintf("API error (%s): %s", e.Status, e.Body)
|
||||
}
|
||||
|
||||
func (e *HTTPError) StatusCode() int {
|
||||
if e == nil {
|
||||
return 0
|
||||
}
|
||||
return e.Code
|
||||
}
|
||||
|
||||
func (e *HTTPError) RetryAfter() time.Duration {
|
||||
if e == nil {
|
||||
return 0
|
||||
}
|
||||
return parseRetryAfter(e.Header.Get("Retry-After"), time.Now())
|
||||
}
|
||||
|
||||
func NewHTTPError(resp *http.Response, body []byte) error {
|
||||
if resp == nil {
|
||||
return errors.New("API error: nil response")
|
||||
}
|
||||
return &HTTPError{Status: resp.Status, Code: resp.StatusCode, Body: string(body), Header: resp.Header.Clone()}
|
||||
}
|
||||
|
||||
func parseRetryAfter(value string, now time.Time) time.Duration {
|
||||
value = strings.TrimSpace(value)
|
||||
if value == "" {
|
||||
return 0
|
||||
}
|
||||
if seconds, err := strconv.Atoi(value); err == nil {
|
||||
if seconds <= 0 {
|
||||
return 0
|
||||
}
|
||||
return time.Duration(seconds) * time.Second
|
||||
}
|
||||
when, err := http.ParseTime(value)
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
if delay := when.Sub(now); delay > 0 {
|
||||
return delay
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// ErrorKind classifies provider-boundary failures into stable buckets callers
|
||||
// can inspect without parsing provider-specific error strings.
|
||||
type ErrorKind string
|
||||
@@ -97,7 +157,7 @@ func GenerateWithRetry(ctx context.Context, m Model, req *Request, policy Genera
|
||||
info.MaxAttempts = policy.MaxAttempts
|
||||
callCtx = WithRunInfo(callCtx, info)
|
||||
}
|
||||
resp, err := m.Generate(callCtx, req, opts...)
|
||||
resp, err := generateAttempt(callCtx, m, req, opts...)
|
||||
cancel()
|
||||
|
||||
// Caller cancellation/deadline always wins and is not retried, even if
|
||||
@@ -137,6 +197,27 @@ func GenerateWithRetry(ctx context.Context, m Model, req *Request, policy Genera
|
||||
return nil, &RetryError{Attempts: policy.MaxAttempts, Kind: ClassifyError(last), Err: last}
|
||||
}
|
||||
|
||||
func generateAttempt(ctx context.Context, m Model, req *Request, opts ...GenerateOption) (*Response, error) {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
type result struct {
|
||||
resp *Response
|
||||
err error
|
||||
}
|
||||
done := make(chan result, 1)
|
||||
go func() {
|
||||
resp, err := m.Generate(ctx, req, opts...)
|
||||
done <- result{resp: resp, err: err}
|
||||
}()
|
||||
select {
|
||||
case res := <-done:
|
||||
return res.resp, res.err
|
||||
case <-ctx.Done():
|
||||
return nil, ctx.Err()
|
||||
}
|
||||
}
|
||||
|
||||
func retryBackoff(err error, attempt int, base time.Duration) time.Duration {
|
||||
backoff := base
|
||||
if backoff <= 0 {
|
||||
|
||||
+162
-4
@@ -3,6 +3,8 @@ package ai
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
@@ -68,9 +70,9 @@ func TestGenerateWithRetryDoesNotRetryCallerCancellation(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGenerateWithRetryHonorsPerAttemptTimeout(t *testing.T) {
|
||||
attempts := 0
|
||||
var attempts atomic.Int32
|
||||
model := retryModel{generate: func(ctx context.Context, _ *Request, _ ...GenerateOption) (*Response, error) {
|
||||
attempts++
|
||||
attempts.Add(1)
|
||||
<-ctx.Done()
|
||||
return nil, ctx.Err()
|
||||
}}
|
||||
@@ -90,8 +92,8 @@ func TestGenerateWithRetryHonorsPerAttemptTimeout(t *testing.T) {
|
||||
if !errors.Is(err, context.DeadlineExceeded) {
|
||||
t.Fatalf("error = %v, want context.DeadlineExceeded", err)
|
||||
}
|
||||
if attempts != 2 {
|
||||
t.Fatalf("attempts = %d, want 2", attempts)
|
||||
if got := attempts.Load(); got != 2 {
|
||||
t.Fatalf("attempts = %d, want 2", got)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,6 +136,34 @@ func TestGenerateWithRetryAddsAttemptMetadataToRunInfo(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestGenerateWithRetryReturnsWhenProviderIgnoresTimeout(t *testing.T) {
|
||||
started := make(chan struct{})
|
||||
release := make(chan struct{})
|
||||
model := retryModel{generate: func(ctx context.Context, req *Request, opts ...GenerateOption) (*Response, error) {
|
||||
close(started)
|
||||
<-release
|
||||
return &Response{Reply: "late"}, nil
|
||||
}}
|
||||
defer close(release)
|
||||
|
||||
start := time.Now()
|
||||
_, err := GenerateWithRetry(context.Background(), model, &Request{Prompt: "hi"}, GeneratePolicy{
|
||||
Timeout: 10 * time.Millisecond,
|
||||
MaxAttempts: 1,
|
||||
})
|
||||
if !errors.Is(err, context.DeadlineExceeded) {
|
||||
t.Fatalf("GenerateWithRetry error = %v, want deadline exceeded", err)
|
||||
}
|
||||
if elapsed := time.Since(start); elapsed > 200*time.Millisecond {
|
||||
t.Fatalf("GenerateWithRetry took %s after deadline, want prompt return", elapsed)
|
||||
}
|
||||
select {
|
||||
case <-started:
|
||||
default:
|
||||
t.Fatal("provider was not called")
|
||||
}
|
||||
}
|
||||
|
||||
type statusErr int
|
||||
|
||||
func (e statusErr) Error() string { return "provider status" }
|
||||
@@ -221,3 +251,131 @@ func TestGenerateWithRetryCapsRetryAfter(t *testing.T) {
|
||||
t.Fatalf("retryBackoff() = %s, want 30s cap", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGenerateWithRetryDoesNotRetryPermanentProviderErrors(t *testing.T) {
|
||||
attempts := 0
|
||||
model := retryModel{generate: func(context.Context, *Request, ...GenerateOption) (*Response, error) {
|
||||
attempts++
|
||||
return nil, statusErr(400)
|
||||
}}
|
||||
|
||||
_, err := GenerateWithRetry(context.Background(), model, &Request{Prompt: "hi"}, GeneratePolicy{
|
||||
MaxAttempts: 3,
|
||||
Backoff: time.Millisecond,
|
||||
})
|
||||
if !errors.Is(err, statusErr(400)) {
|
||||
t.Fatalf("error = %v, want original provider status", err)
|
||||
}
|
||||
var retryErr *RetryError
|
||||
if errors.As(err, &retryErr) {
|
||||
t.Fatalf("error = %T %[1]v, want permanent provider error without retry wrapper", err)
|
||||
}
|
||||
if attempts != 1 {
|
||||
t.Fatalf("attempts = %d, want no retry for permanent provider errors", attempts)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGenerateWithRetryDefaultsToSingleAttempt(t *testing.T) {
|
||||
attempts := 0
|
||||
model := retryModel{generate: func(context.Context, *Request, ...GenerateOption) (*Response, error) {
|
||||
attempts++
|
||||
return nil, errors.New("temporary provider outage")
|
||||
}}
|
||||
|
||||
_, err := GenerateWithRetry(context.Background(), model, &Request{Prompt: "hi"}, GeneratePolicy{
|
||||
Backoff: time.Millisecond,
|
||||
})
|
||||
var retryErr *RetryError
|
||||
if !errors.As(err, &retryErr) {
|
||||
t.Fatalf("error = %T %[1]v, want retry error for exhausted transient attempt", err)
|
||||
}
|
||||
if retryErr.Attempts != 1 {
|
||||
t.Fatalf("retry attempts = %d, want default single attempt", retryErr.Attempts)
|
||||
}
|
||||
if attempts != 1 {
|
||||
t.Fatalf("model attempts = %d, want default single attempt", attempts)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGenerateWithRetryStopsDuringBackoffWhenCallerCancels(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
var attempts atomic.Int32
|
||||
model := retryModel{generate: func(context.Context, *Request, ...GenerateOption) (*Response, error) {
|
||||
attempts.Add(1)
|
||||
return nil, statusErr(503)
|
||||
}}
|
||||
|
||||
errc := make(chan error, 1)
|
||||
go func() {
|
||||
_, err := GenerateWithRetry(ctx, model, &Request{Prompt: "hi"}, GeneratePolicy{
|
||||
MaxAttempts: 3,
|
||||
Backoff: time.Hour,
|
||||
})
|
||||
errc <- err
|
||||
}()
|
||||
|
||||
deadline := time.After(time.Second)
|
||||
for attempts.Load() == 0 {
|
||||
select {
|
||||
case err := <-errc:
|
||||
t.Fatalf("GenerateWithRetry returned before first attempt cancellation: %v", err)
|
||||
case <-deadline:
|
||||
t.Fatal("provider was not called")
|
||||
default:
|
||||
time.Sleep(time.Millisecond)
|
||||
}
|
||||
}
|
||||
|
||||
start := time.Now()
|
||||
cancel()
|
||||
select {
|
||||
case err := <-errc:
|
||||
if !errors.Is(err, context.Canceled) {
|
||||
t.Fatalf("error = %v, want context.Canceled", err)
|
||||
}
|
||||
case <-time.After(200 * time.Millisecond):
|
||||
t.Fatal("GenerateWithRetry did not stop promptly during backoff cancellation")
|
||||
}
|
||||
if elapsed := time.Since(start); elapsed > 200*time.Millisecond {
|
||||
t.Fatalf("backoff cancellation took %s, want prompt return", elapsed)
|
||||
}
|
||||
if got := attempts.Load(); got != 1 {
|
||||
t.Fatalf("attempts = %d, want cancellation before retry", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRetryBackoffUsesExponentialBaseAndCap(t *testing.T) {
|
||||
if got := retryBackoff(statusErr(503), 1, 10*time.Millisecond); got != 10*time.Millisecond {
|
||||
t.Fatalf("attempt 1 backoff = %s, want 10ms", got)
|
||||
}
|
||||
if got := retryBackoff(statusErr(503), 2, 10*time.Millisecond); got != 20*time.Millisecond {
|
||||
t.Fatalf("attempt 2 backoff = %s, want 20ms", got)
|
||||
}
|
||||
if got := retryBackoff(statusErr(503), 3, 10*time.Millisecond); got != 40*time.Millisecond {
|
||||
t.Fatalf("attempt 3 backoff = %s, want 40ms", got)
|
||||
}
|
||||
if got := retryBackoff(statusErr(503), 20, time.Second); got != 30*time.Second {
|
||||
t.Fatalf("large backoff = %s, want 30s cap", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHTTPErrorExposesStatusAndRetryAfter(t *testing.T) {
|
||||
resp := &http.Response{
|
||||
Status: "429 Too Many Requests",
|
||||
StatusCode: http.StatusTooManyRequests,
|
||||
Header: http.Header{"Retry-After": []string{"2"}},
|
||||
}
|
||||
err := NewHTTPError(resp, []byte("slow down"))
|
||||
|
||||
if got := ClassifyError(err); got != ErrorKindRateLimited {
|
||||
t.Fatalf("ClassifyError() = %q, want %q", got, ErrorKindRateLimited)
|
||||
}
|
||||
var retryAfter RetryAfterCoder
|
||||
if !errors.As(err, &retryAfter) {
|
||||
t.Fatalf("NewHTTPError does not expose RetryAfterCoder")
|
||||
}
|
||||
if got := retryAfter.RetryAfter(); got != 2*time.Second {
|
||||
t.Fatalf("RetryAfter() = %s, want 2s", got)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ func init() {
|
||||
return NewProvider(opts...)
|
||||
})
|
||||
ai.RegisterStream("together")
|
||||
ai.RegisterToolStream("together")
|
||||
}
|
||||
|
||||
type Provider struct {
|
||||
@@ -147,7 +148,7 @@ func (p *Provider) callAPI(ctx context.Context, req map[string]any) (*ai.Respons
|
||||
|
||||
respBody, _ := io.ReadAll(httpResp.Body)
|
||||
if httpResp.StatusCode != http.StatusOK {
|
||||
return nil, nil, fmt.Errorf("API error (%s): %s", httpResp.Status, string(respBody))
|
||||
return nil, nil, ai.NewHTTPError(httpResp, respBody)
|
||||
}
|
||||
|
||||
var chatResp struct {
|
||||
|
||||
+3
-2
@@ -67,10 +67,11 @@ provider-free agent path:
|
||||
```
|
||||
micro agent demo
|
||||
micro examples
|
||||
micro zero-to-hero
|
||||
```
|
||||
|
||||
Those commands point at the smallest mock-model first-agent example, the no-secret
|
||||
transcript, and the support app before you add provider-backed chat.
|
||||
transcript, and the 0→hero support app before you add provider-backed chat.
|
||||
|
||||
### Output
|
||||
|
||||
@@ -683,7 +684,7 @@ micro loop init \
|
||||
```
|
||||
|
||||
- `--roles`: which roles to scaffold (`planner,builder,triage`, or `all`)
|
||||
- `--agent`: how the workflows summon the agent (an `@mention`)
|
||||
- `--agent`: how the workflows summon the agent — any `@mention`-driven coding agent (e.g. `@codex`, `@claude`)
|
||||
- `--token-secret`: repo secret holding the driving user PAT
|
||||
- `--branch`: base branch for the loop's PRs
|
||||
- `--ci-workflow`: `name:` of the CI workflow triage watches
|
||||
|
||||
+30
-18
@@ -74,7 +74,9 @@ a new service automatically and start using it.
|
||||
|
||||
Examples:
|
||||
ANTHROPIC_API_KEY=sk-ant-... micro chat --provider anthropic
|
||||
micro chat --provider openai --prompt "list all users"`,
|
||||
micro chat --provider openai --prompt "list all users"
|
||||
micro chat assistant --prompt "create a task"`,
|
||||
ArgsUsage: "[agent]",
|
||||
Flags: []cli.Flag{
|
||||
&cli.StringFlag{Name: "provider", Usage: "AI provider (anthropic, openai, gemini, groq, mistral, together, atlascloud)", EnvVars: []string{"MICRO_AI_PROVIDER"}},
|
||||
&cli.StringFlag{Name: "api_key", Usage: "API key for the provider", EnvVars: []string{"MICRO_AI_API_KEY"}},
|
||||
@@ -316,6 +318,7 @@ func run(c *cli.Context) error {
|
||||
baseURL := c.String("base_url")
|
||||
singlePrompt := c.String("prompt")
|
||||
streamOutput := c.Bool("stream")
|
||||
targetAgent := c.Args().First()
|
||||
|
||||
if provider == "" {
|
||||
provider = ai.AutoDetectProvider(baseURL)
|
||||
@@ -323,15 +326,36 @@ func run(c *cli.Context) error {
|
||||
if apiKey == "" {
|
||||
apiKey = fallbackAPIKey(provider)
|
||||
}
|
||||
if apiKey == "" {
|
||||
return fmt.Errorf("no API key configured; set --api_key or %s", envVarForProvider(provider))
|
||||
}
|
||||
|
||||
reg := registry.DefaultRegistry
|
||||
cl := clt.DefaultClient
|
||||
|
||||
tools := ai.NewTools(reg, ai.ToolClient(cl))
|
||||
|
||||
s := &session{
|
||||
provider: provider,
|
||||
apiKey: apiKey,
|
||||
tools: tools,
|
||||
reg: reg,
|
||||
cl: cl,
|
||||
hist: ai.NewHistory(50),
|
||||
stream: streamOutput,
|
||||
}
|
||||
hasAgents := s.discoverAgents()
|
||||
if targetAgent != "" {
|
||||
if _, ok := s.agents[targetAgent]; !ok {
|
||||
return fmt.Errorf("agent %q is not registered; run `micro agent list` to see available agents", targetAgent)
|
||||
}
|
||||
s.agents = map[string]agentInfo{targetAgent: s.agents[targetAgent]}
|
||||
hasAgents = true
|
||||
}
|
||||
if targetAgent != "" && singlePrompt != "" {
|
||||
return s.ask(c.Context, singlePrompt)
|
||||
}
|
||||
if apiKey == "" {
|
||||
return fmt.Errorf("no API key configured; set --api_key or %s", envVarForProvider(provider))
|
||||
}
|
||||
|
||||
// Built-in agent capabilities (plan, delegate), reused from the
|
||||
// agent package so the direct-service fallback matches a real agent.
|
||||
builtinTools, builtinHandle := agent.Builtins(
|
||||
@@ -343,17 +367,8 @@ func run(c *cli.Context) error {
|
||||
agent.APIKey(apiKey),
|
||||
)
|
||||
|
||||
s := &session{
|
||||
provider: provider,
|
||||
apiKey: apiKey,
|
||||
tools: tools,
|
||||
reg: reg,
|
||||
cl: cl,
|
||||
hist: ai.NewHistory(50),
|
||||
builtinTools: builtinTools,
|
||||
builtinHandle: builtinHandle,
|
||||
stream: streamOutput,
|
||||
}
|
||||
s.builtinTools = builtinTools
|
||||
s.builtinHandle = builtinHandle
|
||||
s.refreshTools()
|
||||
|
||||
// Wrap the tool handler to intercept generate calls
|
||||
@@ -387,9 +402,6 @@ func run(c *cli.Context) error {
|
||||
|
||||
defer s.cleanup()
|
||||
|
||||
// Discover registered agents
|
||||
hasAgents := s.discoverAgents()
|
||||
|
||||
if singlePrompt != "" {
|
||||
return s.ask(c.Context, singlePrompt)
|
||||
}
|
||||
|
||||
@@ -14,6 +14,32 @@ import (
|
||||
"go-micro.dev/v6/store"
|
||||
)
|
||||
|
||||
const firstAgentQuickChecksHelp = `First-agent failure-mode quick checks
|
||||
|
||||
Use this when scaffold -> run -> chat -> inspect stalls and you want the
|
||||
smallest provider-free recovery loop before reading the full docs.
|
||||
|
||||
1. Confirm prerequisites before starting the gateway:
|
||||
micro agent preflight
|
||||
|
||||
2. Start the project and keep it running in a separate terminal:
|
||||
micro run
|
||||
|
||||
3. Check the agent is registered and the chat gateway is reachable:
|
||||
micro agent doctor
|
||||
|
||||
4. If chat returns an answer or an error, inspect the latest run state:
|
||||
micro inspect agent <name>
|
||||
micro runs <name>
|
||||
|
||||
5. If provider chat is not configured yet, prove the no-secret path still works:
|
||||
micro agent demo
|
||||
go test ./internal/harness/zero-to-hero-ci -run TestNoSecretFirstAgentTranscript -count=1
|
||||
|
||||
Recovery docs:
|
||||
https://go-micro.dev/docs/guides/debugging-agents.html
|
||||
https://go-micro.dev/docs/guides/no-secret-first-agent.html`
|
||||
|
||||
const noSecretDemoHelp = `No-secret first-agent demo
|
||||
|
||||
Use this when you want the fastest provider-free agent success path before
|
||||
@@ -72,6 +98,18 @@ for live-provider chat and inspect/debugging.`,
|
||||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "quickcheck",
|
||||
Aliases: []string{"debug"},
|
||||
Usage: "Print first-agent failure-mode quick checks",
|
||||
Description: `Print provider-free recovery breadcrumbs for the scaffold -> run ->
|
||||
chat -> inspect loop, including exact commands for registration, gateway, run
|
||||
history, and no-secret fallback checks.`,
|
||||
Action: func(c *cli.Context) error {
|
||||
fmt.Fprintln(c.App.Writer, firstAgentQuickChecksHelp)
|
||||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "preflight",
|
||||
Usage: "Check local prerequisites before the first provider-backed agent",
|
||||
@@ -224,14 +262,44 @@ func writeRunIndex(w io.Writer, name string, runs []goagent.RunSummary, asJSON b
|
||||
if run.TraceID != "" {
|
||||
line += " trace=" + shortTraceID(run.TraceID)
|
||||
}
|
||||
if run.Checkpoint != "" {
|
||||
line += " checkpoint=" + run.Checkpoint
|
||||
}
|
||||
if run.Stage != "" {
|
||||
line += " stage=" + run.Stage
|
||||
}
|
||||
if run.LastError != "" {
|
||||
line += " error=" + run.LastError
|
||||
}
|
||||
fmt.Fprintln(w, line)
|
||||
writeRunIndexBreadcrumbs(w, name, run)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func writeRunIndexBreadcrumbs(w io.Writer, name string, run goagent.RunSummary) {
|
||||
if run.Stage == "input-required" {
|
||||
fmt.Fprintf(w, " inspect: micro agent history %s %s\n", name, run.RunID)
|
||||
fmt.Fprintf(w, " input: call micro.AgentResumeInput(ctx, agent, %q, input) to continue the input-required run\n", run.RunID)
|
||||
return
|
||||
}
|
||||
if !isResumableRunSummary(run) {
|
||||
return
|
||||
}
|
||||
fmt.Fprintf(w, " inspect: micro agent history %s %s\n", name, run.RunID)
|
||||
fmt.Fprintf(w, " resume: call micro.AgentResume(ctx, agent, %q) after recreating the agent with the same checkpoint store\n", run.RunID)
|
||||
fmt.Fprintf(w, " stream: call micro.ResumeStreamAsk(ctx, agent, %q) to resume with streaming events\n", run.RunID)
|
||||
}
|
||||
|
||||
func isResumableRunSummary(run goagent.RunSummary) bool {
|
||||
switch run.Status {
|
||||
case "running", "error", "failed", "refused":
|
||||
return run.Checkpoint != "done" || run.Stage != ""
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func printRunHistory(name, runID string, asJSON bool) error {
|
||||
events, err := goagent.LoadRunEvents(store.DefaultStore, name, runID)
|
||||
if err != nil {
|
||||
|
||||
@@ -59,6 +59,46 @@ func TestWriteRunIndexHumanIncludesStatusAndDuration(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestWriteRunIndexIncludesResumeBreadcrumbs(t *testing.T) {
|
||||
runs := []goagent.RunSummary{{
|
||||
RunID: "run-failed",
|
||||
Agent: "runner",
|
||||
UpdatedAt: time.Date(2026, 6, 25, 12, 34, 56, 0, time.UTC),
|
||||
Events: 3,
|
||||
Status: "error",
|
||||
LastKind: "tool",
|
||||
Checkpoint: "failed",
|
||||
Stage: "ask",
|
||||
}}
|
||||
var out bytes.Buffer
|
||||
if err := writeRunIndex(&out, "runner", runs, false); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got := out.String()
|
||||
for _, want := range []string{"checkpoint=failed", "stage=ask", `micro agent history runner run-failed`, `micro.AgentResume(ctx, agent, "run-failed")`, `micro.ResumeStreamAsk(ctx, agent, "run-failed")`} {
|
||||
if !strings.Contains(got, want) {
|
||||
t.Fatalf("output missing %q:\n%s", want, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestWriteRunIndexInputRequiredUsesResumeInput(t *testing.T) {
|
||||
runs := []goagent.RunSummary{{RunID: "run-input", Agent: "runner", Status: "running", LastKind: "checkpoint", Checkpoint: "paused", Stage: "input-required"}}
|
||||
var out bytes.Buffer
|
||||
if err := writeRunIndex(&out, "runner", runs, false); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got := out.String()
|
||||
for _, want := range []string{`micro agent history runner run-input`, `micro.AgentResumeInput(ctx, agent, "run-input", input)`} {
|
||||
if !strings.Contains(got, want) {
|
||||
t.Fatalf("output missing %q:\n%s", want, got)
|
||||
}
|
||||
}
|
||||
if strings.Contains(got, `micro.AgentResume(ctx, agent, "run-input")`) || strings.Contains(got, "ResumeStreamAsk") {
|
||||
t.Fatalf("input-required run should point at ResumeInput only, got:\n%s", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWriteRunHistoryHumanAndJSON(t *testing.T) {
|
||||
events := []goagent.RunEvent{{
|
||||
Time: time.Date(2026, 6, 25, 12, 34, 56, 7_000_000, time.UTC),
|
||||
|
||||
@@ -73,3 +73,24 @@ func TestRunAgentDoctorReportsActionableRecoveryFailures(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestAgentQuickcheckPrintsProviderFreeFailureModeBreadcrumbs(t *testing.T) {
|
||||
got := firstAgentQuickChecksHelp
|
||||
for _, want := range []string{
|
||||
"First-agent failure-mode quick checks",
|
||||
"scaffold -> run -> chat -> inspect",
|
||||
"micro agent preflight",
|
||||
"micro run",
|
||||
"micro agent doctor",
|
||||
"micro inspect agent <name>",
|
||||
"micro runs <name>",
|
||||
"micro agent demo",
|
||||
"go test ./internal/harness/zero-to-hero-ci -run TestNoSecretFirstAgentTranscript -count=1",
|
||||
"debugging-agents.html",
|
||||
"no-secret-first-agent.html",
|
||||
} {
|
||||
if !strings.Contains(got, want) {
|
||||
t.Fatalf("quickcheck output missing %q:\n%s", want, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,6 +82,9 @@ const docsWayfinding = `First-agent and 0→hero docs:
|
||||
prove service tools, mock-model chat, and inspectable run history without
|
||||
configuring a provider key.
|
||||
|
||||
If scaffold → run → chat → inspect stalls, print the short recovery map:
|
||||
micro agent quickcheck
|
||||
|
||||
2. No-secret first-agent transcript
|
||||
https://go-micro.dev/docs/guides/no-secret-first-agent.html
|
||||
Run the maintained support agent without a provider key:
|
||||
|
||||
@@ -31,7 +31,7 @@ func TestZeroToOneContract(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
generated.replaceModule(t)
|
||||
generated.assertLocalModule(t)
|
||||
generated.build(t)
|
||||
generated.run(t)
|
||||
generated.call(t, "Alice", "Hello Alice")
|
||||
@@ -52,7 +52,7 @@ func TestZeroToOneNoMCPContract(t *testing.T) {
|
||||
t.Fatalf("--no-mcp generated main.go with MCP wiring:\n%s", main)
|
||||
}
|
||||
|
||||
generated.replaceModule(t)
|
||||
generated.assertLocalModule(t)
|
||||
generated.build(t)
|
||||
generated.run(t)
|
||||
generated.call(t, "Bob", "Hello Bob")
|
||||
@@ -112,6 +112,7 @@ func generateService(t *testing.T, name string, args ...string) generatedService
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Setenv("MICRO_NEW_GO_MICRO_REPLACE", repoRoot)
|
||||
|
||||
tmp := t.TempDir()
|
||||
oldwd, err := os.Getwd()
|
||||
@@ -142,7 +143,7 @@ func generateService(t *testing.T, name string, args ...string) generatedService
|
||||
return generatedService{dir: filepath.Join(tmp, name), repoRoot: repoRoot}
|
||||
}
|
||||
|
||||
func (g generatedService) replaceModule(t *testing.T) {
|
||||
func (g generatedService) assertLocalModule(t *testing.T) {
|
||||
t.Helper()
|
||||
|
||||
modPath := filepath.Join(g.dir, "go.mod")
|
||||
@@ -150,10 +151,9 @@ func (g generatedService) replaceModule(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
modText := strings.Replace(string(mod), "go-micro.dev/v6 latest", "go-micro.dev/v6 v6.0.0", 1)
|
||||
modText += "\nreplace go-micro.dev/v6 => " + filepath.ToSlash(g.repoRoot) + "\n"
|
||||
if err := os.WriteFile(modPath, []byte(modText), 0644); err != nil {
|
||||
t.Fatal(err)
|
||||
want := "replace go-micro.dev/v6 => " + filepath.ToSlash(g.repoRoot)
|
||||
if !strings.Contains(string(mod), want) {
|
||||
t.Fatalf("generated go.mod missing local replace %q:\n%s", want, mod)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,8 @@ type config struct {
|
||||
UseGoPath bool
|
||||
// MicroVersion is the go-micro version to require in go.mod
|
||||
MicroVersion string
|
||||
// MicroReplace optionally points generated services at a local go-micro checkout.
|
||||
MicroReplace string
|
||||
// Files
|
||||
Files []file
|
||||
// Comments
|
||||
@@ -69,6 +71,10 @@ func microVersion() string {
|
||||
return "latest"
|
||||
}
|
||||
|
||||
func microReplace() string {
|
||||
return filepath.ToSlash(os.Getenv("MICRO_NEW_GO_MICRO_REPLACE"))
|
||||
}
|
||||
|
||||
type file struct {
|
||||
Path string
|
||||
Tmpl string
|
||||
@@ -215,6 +221,7 @@ func Run(ctx *cli.Context) error {
|
||||
GoPath: goPath,
|
||||
UseGoPath: false,
|
||||
MicroVersion: microVersion(),
|
||||
MicroReplace: microReplace(),
|
||||
}
|
||||
|
||||
if useProto {
|
||||
|
||||
@@ -10,7 +10,9 @@ require (
|
||||
github.com/golang/protobuf latest
|
||||
google.golang.org/protobuf latest
|
||||
)
|
||||
`
|
||||
{{if .MicroReplace}}
|
||||
replace go-micro.dev/v6 => {{.MicroReplace}}
|
||||
{{end}}`
|
||||
|
||||
// ModuleNoProto is the default go.mod: no protobuf dependencies.
|
||||
// MicroVersion is the version this CLI was built from (or "latest"), so a
|
||||
@@ -20,5 +22,7 @@ require (
|
||||
go 1.23
|
||||
|
||||
require go-micro.dev/v6 {{.MicroVersion}}
|
||||
`
|
||||
{{if .MicroReplace}}
|
||||
replace go-micro.dev/v6 => {{.MicroReplace}}
|
||||
{{end}}`
|
||||
)
|
||||
|
||||
@@ -2,6 +2,8 @@ package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -36,12 +38,15 @@ func TestFirstAgentWalkthroughCLIBoundaries(t *testing.T) {
|
||||
if !subcommands["agent"]["doctor"] {
|
||||
t.Fatal("first-agent walkthrough missing recovery boundary: agent doctor")
|
||||
}
|
||||
if !subcommands["agent"]["quickcheck"] {
|
||||
t.Fatal("first-agent walkthrough missing failure-mode boundary: agent quickcheck")
|
||||
}
|
||||
if !subcommands["inspect"]["agent"] {
|
||||
t.Fatal("first-agent walkthrough missing inspect boundary: inspect agent")
|
||||
}
|
||||
|
||||
chat := commandByName(t, "chat")
|
||||
if !strings.Contains(chat.Description, "services") || !strings.Contains(chat.Description, "agent") {
|
||||
if !strings.Contains(chat.Description, "services") || !strings.Contains(chat.Description, "agent") || !strings.Contains(chat.Description, `micro chat assistant --prompt`) {
|
||||
t.Fatalf("micro chat should describe the service-to-agent walkthrough boundary; description was %q", chat.Description)
|
||||
}
|
||||
|
||||
@@ -116,6 +121,28 @@ func TestFirstAgentWalkthroughCLIBoundaries(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
quickcheck := subcommandByName(t, agent, "quickcheck")
|
||||
out.Reset()
|
||||
if err := quickcheck.Action(cli.NewContext(app, nil, nil)); err != nil {
|
||||
t.Fatalf("micro agent quickcheck failed: %v", err)
|
||||
}
|
||||
for _, want := range []string{
|
||||
"First-agent failure-mode quick checks",
|
||||
"scaffold -> run -> chat -> inspect",
|
||||
"micro agent preflight",
|
||||
"micro run",
|
||||
"micro agent doctor",
|
||||
"micro inspect agent <name>",
|
||||
"micro runs <name>",
|
||||
"micro agent demo",
|
||||
"go test ./internal/harness/zero-to-hero-ci -run TestNoSecretFirstAgentTranscript -count=1",
|
||||
"debugging-agents.html",
|
||||
} {
|
||||
if !strings.Contains(out.String(), want) {
|
||||
t.Fatalf("micro agent quickcheck output missing %q:\n%s", want, out.String())
|
||||
}
|
||||
}
|
||||
|
||||
demo := subcommandByName(t, agent, "demo")
|
||||
out.Reset()
|
||||
if err := demo.Action(cli.NewContext(app, nil, nil)); err != nil {
|
||||
@@ -139,6 +166,135 @@ func TestFirstAgentWalkthroughCLIBoundaries(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestFirstAgentDocsMatchCLIOutput(t *testing.T) {
|
||||
root := filepath.Clean(filepath.Join("..", ".."))
|
||||
outputs := map[string]string{
|
||||
"micro docs": commandOutput(t, commandByName(t, "docs")),
|
||||
"micro examples": commandOutput(t, commandByName(t, "examples")),
|
||||
"micro zero-to-hero": commandOutput(t, commandByName(t, "zero-to-hero")),
|
||||
}
|
||||
agent := commandByName(t, "agent")
|
||||
outputs["micro agent demo"] = commandOutput(t, subcommandByName(t, agent, "demo"))
|
||||
outputs["micro agent quickcheck"] = commandOutput(t, subcommandByName(t, agent, "quickcheck"))
|
||||
|
||||
contracts := []struct {
|
||||
name string
|
||||
file string
|
||||
markers []string
|
||||
}{
|
||||
{
|
||||
name: "README first-agent on-ramp",
|
||||
file: filepath.Join(root, "README.md"),
|
||||
markers: []string{
|
||||
"micro agent demo",
|
||||
"micro agent quickcheck",
|
||||
"micro agent preflight",
|
||||
"micro agent doctor",
|
||||
"micro inspect agent <name>",
|
||||
"micro examples",
|
||||
"micro zero-to-hero",
|
||||
"examples/first-agent/",
|
||||
"examples/support/",
|
||||
"internal/website/docs/guides/no-secret-first-agent.md",
|
||||
"internal/website/docs/guides/your-first-agent.md",
|
||||
"internal/website/docs/guides/debugging-agents.md",
|
||||
"internal/website/docs/guides/zero-to-hero.md",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "website getting-started first-agent on-ramp",
|
||||
file: filepath.Join(root, "internal", "website", "docs", "getting-started.md"),
|
||||
markers: []string{
|
||||
"micro agent demo",
|
||||
"micro agent quickcheck",
|
||||
"micro agent preflight",
|
||||
"micro agent doctor",
|
||||
"micro inspect agent <name>",
|
||||
"micro examples",
|
||||
"micro zero-to-hero",
|
||||
"github.com/micro/go-micro/tree/master/examples/first-agent",
|
||||
"github.com/micro/go-micro/tree/master/examples/support",
|
||||
"guides/no-secret-first-agent.html",
|
||||
"guides/your-first-agent.html",
|
||||
"guides/debugging-agents.html",
|
||||
"guides/zero-to-hero.html",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, contract := range contracts {
|
||||
doc := readTestFile(t, contract.file)
|
||||
for _, marker := range contract.markers {
|
||||
if !strings.Contains(doc, marker) {
|
||||
t.Fatalf("%s missing documented first-agent marker %q", contract.name, marker)
|
||||
}
|
||||
if isCLIContractMarker(marker) && !cliOutputsContain(outputs, marker) {
|
||||
t.Fatalf("%s documents %q, but none of the first-agent CLI outputs mention it; keep README/website breadcrumbs aligned with micro agent demo/examples/zero-to-hero", contract.name, marker)
|
||||
}
|
||||
assertMaintainedFirstAgentPath(t, root, marker)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func commandOutput(t *testing.T, command *cli.Command) string {
|
||||
t.Helper()
|
||||
var out bytes.Buffer
|
||||
app := cli.NewApp()
|
||||
app.Writer = &out
|
||||
if err := command.Action(cli.NewContext(app, nil, nil)); err != nil {
|
||||
t.Fatalf("%s failed: %v", command.Name, err)
|
||||
}
|
||||
return out.String()
|
||||
}
|
||||
|
||||
func cliOutputsContain(outputs map[string]string, marker string) bool {
|
||||
for command, out := range outputs {
|
||||
if command == marker || strings.Contains(out, marker) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func isCLIContractMarker(marker string) bool {
|
||||
return strings.HasPrefix(marker, "micro ") || strings.HasPrefix(marker, "go run ") || strings.HasPrefix(marker, "go test ") || strings.Contains(marker, ".html")
|
||||
}
|
||||
|
||||
func assertMaintainedFirstAgentPath(t *testing.T, root, marker string) {
|
||||
t.Helper()
|
||||
pathChecks := map[string]string{
|
||||
"go run ./examples/first-agent": "examples/first-agent",
|
||||
"examples/first-agent/": "examples/first-agent",
|
||||
"examples/support/": "examples/support",
|
||||
"internal/website/docs/guides/no-secret-first-agent.md": "internal/website/docs/guides/no-secret-first-agent.md",
|
||||
"internal/website/docs/guides/your-first-agent.md": "internal/website/docs/guides/your-first-agent.md",
|
||||
"internal/website/docs/guides/debugging-agents.md": "internal/website/docs/guides/debugging-agents.md",
|
||||
"internal/website/docs/guides/zero-to-hero.md": "internal/website/docs/guides/zero-to-hero.md",
|
||||
"guides/no-secret-first-agent.html": "internal/website/docs/guides/no-secret-first-agent.md",
|
||||
"guides/your-first-agent.html": "internal/website/docs/guides/your-first-agent.md",
|
||||
"guides/debugging-agents.html": "internal/website/docs/guides/debugging-agents.md",
|
||||
"guides/zero-to-hero.html": "internal/website/docs/guides/zero-to-hero.md",
|
||||
"github.com/micro/go-micro/tree/master/examples/first-agent": "examples/first-agent",
|
||||
"github.com/micro/go-micro/tree/master/examples/support": "examples/support",
|
||||
}
|
||||
path, ok := pathChecks[marker]
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(root, filepath.FromSlash(path))); err != nil {
|
||||
t.Fatalf("documented first-agent path %q from marker %q does not resolve: %v", path, marker, err)
|
||||
}
|
||||
}
|
||||
|
||||
func readTestFile(t *testing.T, path string) string {
|
||||
t.Helper()
|
||||
b, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
t.Fatalf("read %s: %v", path, err)
|
||||
}
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func commandByName(t *testing.T, name string) *cli.Command {
|
||||
t.Helper()
|
||||
for _, command := range microcmd.DefaultCmd.App().Commands {
|
||||
|
||||
@@ -98,16 +98,25 @@ func writeAgentInspection(w io.Writer, name string, runs []goagent.RunSummary, a
|
||||
fmt.Fprintf(w, " trace=%s", shortID(run.TraceID))
|
||||
}
|
||||
fmt.Fprintln(w)
|
||||
if isResumableAgentRun(run) {
|
||||
fmt.Fprintf(w, " resume: call micro.AgentResume(ctx, agent, %q) after recreating the agent with the same checkpoint store\n", run.RunID)
|
||||
}
|
||||
if run.Stage == "input-required" {
|
||||
fmt.Fprintf(w, " input: call micro.AgentResumeInput(ctx, agent, %q, input) to continue the paused run\n", run.RunID)
|
||||
}
|
||||
writeAgentRunBreadcrumbs(w, name, run)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func writeAgentRunBreadcrumbs(w io.Writer, name string, run goagent.RunSummary) {
|
||||
if run.Stage == "input-required" {
|
||||
fmt.Fprintf(w, " inspect: micro agent history %s %s\n", name, run.RunID)
|
||||
fmt.Fprintf(w, " input: call micro.AgentResumeInput(ctx, agent, %q, input) to continue the input-required run\n", run.RunID)
|
||||
return
|
||||
}
|
||||
if !isResumableAgentRun(run) {
|
||||
return
|
||||
}
|
||||
fmt.Fprintf(w, " inspect: micro agent history %s %s\n", name, run.RunID)
|
||||
fmt.Fprintf(w, " resume: call micro.AgentResume(ctx, agent, %q) after recreating the agent with the same checkpoint store\n", run.RunID)
|
||||
fmt.Fprintf(w, " stream: call micro.ResumeStreamAsk(ctx, agent, %q) to resume with streaming events\n", run.RunID)
|
||||
}
|
||||
|
||||
func isResumableAgentRun(run goagent.RunSummary) bool {
|
||||
switch run.Status {
|
||||
case "running", "error", "failed", "refused":
|
||||
|
||||
@@ -17,7 +17,7 @@ func TestWriteAgentInspectionIncludesActionableBreadcrumbs(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got := out.String()
|
||||
for _, want := range []string{"Agent \"support\" runs", "run-1", "status=error", "events=4", "last=tool", "checkpoint=failed", "stage=ask", `error="boom"`, "trace=1234567890ab", `micro.AgentResume(ctx, agent, "run-1")`} {
|
||||
for _, want := range []string{"Agent \"support\" runs", "run-1", "status=error", "events=4", "last=tool", "checkpoint=failed", "stage=ask", `error="boom"`, "trace=1234567890ab", `micro agent history support run-1`, `micro.AgentResume(ctx, agent, "run-1")`, `micro.ResumeStreamAsk(ctx, agent, "run-1")`} {
|
||||
if !strings.Contains(got, want) {
|
||||
t.Fatalf("output missing %q:\n%s", want, got)
|
||||
}
|
||||
@@ -31,11 +31,14 @@ func TestWriteAgentInspectionIncludesInputResumeBreadcrumb(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got := out.String()
|
||||
for _, want := range []string{"checkpoint=paused", "stage=input-required", `micro.AgentResumeInput(ctx, agent, "run-input", input)`} {
|
||||
for _, want := range []string{"checkpoint=paused", "stage=input-required", `micro agent history support run-input`, `micro.AgentResumeInput(ctx, agent, "run-input", input)`} {
|
||||
if !strings.Contains(got, want) {
|
||||
t.Fatalf("output missing %q:\n%s", want, got)
|
||||
}
|
||||
}
|
||||
if strings.Contains(got, `micro.AgentResume(ctx, agent, "run-input")`) || strings.Contains(got, "ResumeStreamAsk") {
|
||||
t.Fatalf("input-required run should point at ResumeInput only, got:\n%s", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWriteAgentInspectionEmptyStateNamesInspectCommand(t *testing.T) {
|
||||
|
||||
@@ -123,7 +123,7 @@ Examples:
|
||||
&cli.StringFlag{Name: "dir", Usage: "Target repo directory", Value: "."},
|
||||
&cli.StringFlag{Name: "roles", Usage: "Comma-separated roles, or 'all'", Value: "planner,builder,triage"},
|
||||
&cli.StringFlag{Name: "branch", Usage: "Base branch for the loop's PRs (auto-detected if empty)"},
|
||||
&cli.StringFlag{Name: "agent", Usage: "How the workflows summon the agent (an @mention)", Value: "@codex"},
|
||||
&cli.StringFlag{Name: "agent", Usage: "How the workflows summon the agent — any @mention-driven coding agent (e.g. @codex, @claude)", Value: "@codex"},
|
||||
&cli.StringFlag{Name: "token-secret", Usage: "Repo secret holding the user PAT that drives dispatch", Value: "LOOP_TOKEN"},
|
||||
&cli.StringFlag{Name: "ci-workflow", Usage: "CI workflow name(s) triage watches for failures (comma-separated)", Value: "CI"},
|
||||
&cli.StringFlag{Name: "planner-cron", Usage: "Cron schedule for the planner", Value: "0 * * * *"},
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
name: "Loop: Release"
|
||||
|
||||
# Generated by `micro loop init`. Cuts the next PATCH tag
|
||||
# (<< .TagPrefix >>MAJOR.MINOR.PATCH+1) when the default branch has new commits
|
||||
# since the latest such tag, and pushes it with a PAT (<< .TokenSecret >>) so any
|
||||
# tag-triggered release workflow fires. Minor/major bumps stay with a human.
|
||||
# Generated by `micro loop init`. Cuts the next tag when the default branch has
|
||||
# new commits since the latest one, and pushes it with a PAT (<< .TokenSecret >>)
|
||||
# so any tag-triggered release workflow fires. The bump reflects what shipped,
|
||||
# read from the CHANGELOG [Unreleased] section: new features (Added/Changed) cut
|
||||
# a MINOR; fixes/docs only cut a PATCH; breaking changes are skipped so a MAJOR
|
||||
# stays a human decision.
|
||||
#
|
||||
# The tag MUST be pushed with a PAT, not the default GITHUB_TOKEN: a tag pushed
|
||||
# by GITHUB_TOKEN does not trigger other workflows (Actions blocks that recursion).
|
||||
@@ -66,11 +68,30 @@ jobs:
|
||||
[0-9]*.[0-9]*.[0-9]*) ;;
|
||||
*) echo "unexpected tag shape: $LATEST" ; exit 1 ;;
|
||||
esac
|
||||
NEXT="<< .TagPrefix >>${major}.${minor}.$((patch + 1))"
|
||||
echo "cutting: $NEXT ($COUNT commits since $LATEST)"
|
||||
|
||||
# Choose the bump from what actually shipped, read from the CHANGELOG
|
||||
# [Unreleased] section (kept current by the coherence role):
|
||||
# new features (### Added / ### Changed) -> MINOR
|
||||
# fixes/docs only -> PATCH
|
||||
# breaking (### Removed / "(breaking)") -> skip; a major is a human call
|
||||
UNRELEASED=""
|
||||
if [ -f CHANGELOG.md ]; then
|
||||
UNRELEASED=$(awk '/^## \[Unreleased\]/{f=1; next} /^## \[/{f=0} f' CHANGELOG.md)
|
||||
fi
|
||||
if printf '%s\n' "$UNRELEASED" | grep -qiE '^### Removed|^### Changed \(breaking\)|BREAKING'; then
|
||||
echo "CHANGELOG [Unreleased] contains breaking changes — a major release is a human decision. Skipping."
|
||||
exit 0
|
||||
elif printf '%s\n' "$UNRELEASED" | grep -qE '^### (Added|Changed)'; then
|
||||
NEXT="<< .TagPrefix >>${major}.$((minor + 1)).0"
|
||||
KIND="minor (new features)"
|
||||
else
|
||||
NEXT="<< .TagPrefix >>${major}.${minor}.$((patch + 1))"
|
||||
KIND="patch (fixes/docs only)"
|
||||
fi
|
||||
echo "cutting: $NEXT — $KIND ($COUNT commits since $LATEST)"
|
||||
|
||||
git config user.name "loop release bot"
|
||||
git config user.email "noreply@users.noreply.github.com"
|
||||
git tag -a "$NEXT" -m "Release $NEXT — automated patch ($COUNT commits since $LATEST)"
|
||||
git tag -a "$NEXT" -m "Release $NEXT — automated $KIND ($COUNT commits since $LATEST)"
|
||||
git push "https://x-access-token:${RELEASE_TOKEN}@github.com/${REPO}.git" "$NEXT"
|
||||
echo "Pushed $NEXT."
|
||||
|
||||
@@ -34,5 +34,22 @@ CI keeps this path runnable with:
|
||||
go test ./examples/first-agent
|
||||
```
|
||||
|
||||
After this, continue to [`examples/support`](../support/) for the full services →
|
||||
agents → workflows lifecycle with a flow trigger and an approval gate.
|
||||
## Next chat, inspect, and debug breadcrumbs
|
||||
|
||||
This example exits after one in-process `assistant.Ask` call so it stays tiny and
|
||||
provider-free. When you move from this transcript to a long-running agent, keep
|
||||
these commands nearby:
|
||||
|
||||
```bash
|
||||
micro run
|
||||
micro chat assistant --prompt "Summarize my next steps"
|
||||
micro inspect agent assistant
|
||||
micro agent doctor assistant
|
||||
```
|
||||
|
||||
Use the [no-secret first-agent guide](../../internal/website/docs/guides/no-secret-first-agent.md)
|
||||
to compare this transcript with the CLI demo, then keep the
|
||||
[debugging guide](../../internal/website/docs/guides/debugging-agents.md) open for
|
||||
preflight, doctor, inspect, and history checks. After that, continue to
|
||||
[`examples/support`](../support/) for the full services → agents → workflows
|
||||
lifecycle with a flow trigger and an approval gate.
|
||||
|
||||
@@ -13,6 +13,7 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -33,13 +34,13 @@ type ListNotesResponse struct {
|
||||
Notes []string `json:"notes" description:"Notes the assistant can summarize"`
|
||||
}
|
||||
|
||||
type NotesService struct{}
|
||||
type NotesService struct{ w io.Writer }
|
||||
|
||||
// List returns the starter notes the first agent can read.
|
||||
// @example {}
|
||||
func (s *NotesService) List(ctx context.Context, req *ListNotesRequest, rsp *ListNotesResponse) error {
|
||||
rsp.Notes = []string{"Install the micro CLI", "Run a service", "Chat with an agent"}
|
||||
fmt.Println(" [notes] listed starter notes")
|
||||
fmt.Fprintln(s.w, " [notes] listed starter notes")
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -90,6 +91,10 @@ func waitFor(reg registry.Registry, names ...string) error {
|
||||
}
|
||||
|
||||
func runFirstAgent() error {
|
||||
return runFirstAgentWithWriter(os.Stdout)
|
||||
}
|
||||
|
||||
func runFirstAgentWithWriter(w io.Writer) error {
|
||||
ai.Register("first-agent-mock", newMock)
|
||||
|
||||
reg := registry.NewMemoryRegistry()
|
||||
@@ -104,7 +109,7 @@ func runFirstAgent() error {
|
||||
cl := client.NewClient(client.Registry(reg), client.Selector(selector.NewSelector(selector.Registry(reg))), client.Broker(br))
|
||||
|
||||
notes := service.New(service.Name("notes"), service.Address("127.0.0.1:0"), service.Registry(reg), service.Client(cl), service.Broker(br), service.HandleSignal(false))
|
||||
if err := notes.Handle(new(NotesService)); err != nil {
|
||||
if err := notes.Handle(&NotesService{w: w}); err != nil {
|
||||
return fmt.Errorf("handle notes: %w", err)
|
||||
}
|
||||
svcErr := make(chan error, 1)
|
||||
@@ -137,14 +142,14 @@ func runFirstAgent() error {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Println("First agent (provider: mock, no API key)")
|
||||
fmt.Println("> Summarize my next steps")
|
||||
fmt.Fprintln(w, "First agent (provider: mock, no API key)")
|
||||
fmt.Fprintln(w, "> Summarize my next steps")
|
||||
resp, err := assistant.Ask(context.Background(), "Summarize my next steps")
|
||||
if err != nil {
|
||||
return fmt.Errorf("ask assistant: %w", err)
|
||||
}
|
||||
fmt.Println("assistant:", resp.Reply)
|
||||
fmt.Println("✓ service-backed agent completed without provider secrets")
|
||||
fmt.Fprintln(w, "assistant:", resp.Reply)
|
||||
fmt.Fprintln(w, "✓ service-backed agent completed without provider secrets")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,71 @@
|
||||
package main
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestRunFirstAgent(t *testing.T) {
|
||||
if err := runFirstAgent(); err != nil {
|
||||
var out bytes.Buffer
|
||||
if err := runFirstAgentWithWriter(&out); err != nil {
|
||||
t.Fatalf("first-agent example failed: %v", err)
|
||||
}
|
||||
|
||||
want := strings.TrimSpace(readExpectedTranscript(t))
|
||||
got := strings.TrimSpace(out.String())
|
||||
if got != want {
|
||||
t.Fatalf("first-agent transcript drifted from README.md\n--- got ---\n%s\n--- want ---\n%s", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestReadmeDocumentsNextBreadcrumbs(t *testing.T) {
|
||||
b, err := os.ReadFile("README.md")
|
||||
if err != nil {
|
||||
t.Fatalf("read README.md: %v", err)
|
||||
}
|
||||
readme := string(b)
|
||||
start := strings.Index(readme, "## Next chat, inspect, and debug breadcrumbs")
|
||||
if start < 0 {
|
||||
t.Fatal("README.md missing next chat, inspect, and debug breadcrumbs section")
|
||||
}
|
||||
section := readme[start:]
|
||||
for _, want := range []string{
|
||||
"micro run",
|
||||
"micro chat assistant --prompt \"Summarize my next steps\"",
|
||||
"micro inspect agent assistant",
|
||||
"micro agent doctor assistant",
|
||||
"no-secret-first-agent.md",
|
||||
"debugging-agents.md",
|
||||
"examples/support",
|
||||
} {
|
||||
if !strings.Contains(section, want) {
|
||||
t.Fatalf("README.md next breadcrumbs missing %q", want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func readExpectedTranscript(t *testing.T) string {
|
||||
t.Helper()
|
||||
b, err := os.ReadFile("README.md")
|
||||
if err != nil {
|
||||
t.Fatalf("read README.md: %v", err)
|
||||
}
|
||||
readme := string(b)
|
||||
const fence = "```text"
|
||||
start := strings.Index(readme, "Expected transcript:")
|
||||
if start < 0 {
|
||||
t.Fatal("README.md missing Expected transcript section")
|
||||
}
|
||||
fenceStart := strings.Index(readme[start:], fence)
|
||||
if fenceStart < 0 {
|
||||
t.Fatal("README.md missing transcript text fence")
|
||||
}
|
||||
start += fenceStart + len(fence)
|
||||
end := strings.Index(readme[start:], "```")
|
||||
if end < 0 {
|
||||
t.Fatal("README.md missing closing transcript fence")
|
||||
}
|
||||
return readme[start : start+end]
|
||||
}
|
||||
|
||||
@@ -54,6 +54,32 @@ agent, which:
|
||||
emailing a customer (`notify.Send`) passes through the gate first. Return
|
||||
`false` to hold it for a person or a policy; the example approves and logs.
|
||||
|
||||
## Expected inspect transcript
|
||||
|
||||
The provider-free run prints the same visible checkpoints a new developer should
|
||||
compare against after chat and flow execution. The transcript includes service
|
||||
tool calls, the approval gate, and the inspect/run-history commands that prove
|
||||
the workflow run was recorded.
|
||||
|
||||
```text
|
||||
> event: events.ticket.created {"customer":"alice@acme.com","id":"ticket-1","subject":"Can't log in"}
|
||||
|
||||
[customers] looked up Alice (pro plan)
|
||||
[tickets] ticket-1 → priority=high status=in_progress
|
||||
▣ approval gate notify_NotifyService_Send(alice@acme.com) — approved
|
||||
[notify] 📨 to=alice@acme.com: "Hi Alice — thanks for reaching out. We've bumped this to high priority and are on it."
|
||||
|
||||
support agent: Triaged ticket-1 for Alice and sent a reply.
|
||||
|
||||
inspect transcript:
|
||||
micro inspect flow intake
|
||||
flow: intake runs=1 latest.reply="Triaged ticket-1 for Alice and sent a reply."
|
||||
micro agent history support
|
||||
agent: support runs=1 latest.status=completed
|
||||
|
||||
✓ ticket triaged and the customer was replied to — triggered by an event
|
||||
```
|
||||
|
||||
## Run
|
||||
|
||||
```bash
|
||||
|
||||
@@ -302,7 +302,13 @@ func runSupport(provider string) error {
|
||||
}
|
||||
|
||||
if rs := intake.Results(); len(rs) > 0 {
|
||||
fmt.Printf("\n\033[1msupport agent:\033[0m %s\n", rs[len(rs)-1].Reply)
|
||||
latest := rs[len(rs)-1]
|
||||
fmt.Printf("\n\033[1msupport agent:\033[0m %s\n", latest.Reply)
|
||||
fmt.Println("\n\033[1minspect transcript:\033[0m")
|
||||
fmt.Println(" micro inspect flow intake")
|
||||
fmt.Printf(" flow: intake runs=%d latest.reply=%q\n", len(rs), latest.Reply)
|
||||
fmt.Println(" micro agent history support")
|
||||
fmt.Printf(" agent: support runs=%d latest.status=completed\n", len(rs))
|
||||
}
|
||||
if notify.sent >= 1 {
|
||||
fmt.Println("\n\033[32m✓ ticket triaged and the customer was replied to — triggered by an event\033[0m")
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
@@ -30,3 +33,78 @@ func TestZeroToHeroReadmeDocumentsLifecycle(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestZeroToHeroInspectTranscript(t *testing.T) {
|
||||
out := captureStdout(t, func() {
|
||||
if err := runSupport("mock"); err != nil {
|
||||
t.Fatalf("support example failed: %v", err)
|
||||
}
|
||||
})
|
||||
got := stripANSI(out)
|
||||
|
||||
for _, want := range []string{
|
||||
`> event: events.ticket.created {"customer":"alice@acme.com","id":"ticket-1","subject":"Can't log in"}`,
|
||||
`[customers] looked up Alice (pro plan)`,
|
||||
`[tickets] ticket-1 → priority=high status=in_progress`,
|
||||
`approval gate notify_NotifyService_Send(alice@acme.com) — approved`,
|
||||
`[notify] 📨 to=alice@acme.com: "Hi Alice — thanks for reaching out. We've bumped this to high priority and are on it."`,
|
||||
`support agent: Triaged ticket-1 for Alice and sent a reply.`,
|
||||
`inspect transcript:`,
|
||||
`micro inspect flow intake`,
|
||||
`flow: intake runs=1 latest.reply="Triaged ticket-1 for Alice and sent a reply."`,
|
||||
`micro agent history support`,
|
||||
`agent: support runs=1 latest.status=completed`,
|
||||
`✓ ticket triaged and the customer was replied to — triggered by an event`,
|
||||
} {
|
||||
if !strings.Contains(got, want) {
|
||||
t.Fatalf("support transcript missing %q\n--- got ---\n%s", want, got)
|
||||
}
|
||||
}
|
||||
|
||||
readme, err := os.ReadFile("README.md")
|
||||
if err != nil {
|
||||
t.Fatalf("read README.md: %v", err)
|
||||
}
|
||||
for _, want := range []string{
|
||||
"Expected inspect transcript",
|
||||
"micro inspect flow intake",
|
||||
"micro agent history support",
|
||||
"agent: support runs=1 latest.status=completed",
|
||||
} {
|
||||
if !strings.Contains(string(readme), want) {
|
||||
t.Fatalf("README.md missing transcript contract %q", want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func captureStdout(t *testing.T, fn func()) (out string) {
|
||||
t.Helper()
|
||||
old := os.Stdout
|
||||
r, w, err := os.Pipe()
|
||||
if err != nil {
|
||||
t.Fatalf("capture stdout: %v", err)
|
||||
}
|
||||
os.Stdout = w
|
||||
|
||||
var buf bytes.Buffer
|
||||
done := make(chan struct{})
|
||||
go func() {
|
||||
_, _ = io.Copy(&buf, r)
|
||||
close(done)
|
||||
}()
|
||||
defer func() {
|
||||
_ = w.Close()
|
||||
os.Stdout = old
|
||||
<-done
|
||||
out = buf.String()
|
||||
}()
|
||||
|
||||
fn()
|
||||
return out
|
||||
}
|
||||
|
||||
var ansiRE = regexp.MustCompile(`\x1b\[[0-9;]*m`)
|
||||
|
||||
func stripANSI(s string) string {
|
||||
return ansiRE.ReplaceAllString(s, "")
|
||||
}
|
||||
|
||||
+35
-5
@@ -627,6 +627,9 @@ func (d *dispatcher) run(ctx context.Context, params json.RawMessage, invoke Inv
|
||||
reply = err.Error()
|
||||
state = stateInputRequired
|
||||
}
|
||||
} else if strings.TrimSpace(reply) == "" {
|
||||
reply = "error: agent returned an empty response"
|
||||
state = stateFailed
|
||||
}
|
||||
task := d.taskFromReply(p.Message, reply, state)
|
||||
d.store(task)
|
||||
@@ -750,13 +753,11 @@ func (g *Gateway) callAgent(ctx context.Context, name, message string) (string,
|
||||
if err := g.opts.Client.Call(ctx, req, &rsp); err != nil {
|
||||
return "", err
|
||||
}
|
||||
var out struct {
|
||||
Reply string `json:"reply"`
|
||||
}
|
||||
if err := json.Unmarshal(rsp.Data, &out); err != nil {
|
||||
reply, err := decodeAgentChatReply(rsp.Data)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return out.Reply, nil
|
||||
return reply, nil
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -976,6 +977,35 @@ func textArtifact(text string) Artifact {
|
||||
}
|
||||
}
|
||||
|
||||
func decodeAgentChatReply(data []byte) (string, error) {
|
||||
var out struct {
|
||||
Reply string `json:"reply"`
|
||||
Answer string `json:"answer"`
|
||||
Content string `json:"content"`
|
||||
Text string `json:"text"`
|
||||
Message struct {
|
||||
Content string `json:"content"`
|
||||
Text string `json:"text"`
|
||||
} `json:"message"`
|
||||
}
|
||||
if err := json.Unmarshal(data, &out); err != nil {
|
||||
return "", err
|
||||
}
|
||||
for _, candidate := range []string{
|
||||
out.Reply,
|
||||
out.Answer,
|
||||
out.Content,
|
||||
out.Text,
|
||||
out.Message.Content,
|
||||
out.Message.Text,
|
||||
} {
|
||||
if strings.TrimSpace(candidate) != "" {
|
||||
return candidate, nil
|
||||
}
|
||||
}
|
||||
return "", nil
|
||||
}
|
||||
|
||||
// requestContext carries request cancellation and deadlines into the downstream
|
||||
// agent call without leaking HTTP transport context values into the go-micro
|
||||
// client stack.
|
||||
|
||||
@@ -523,6 +523,65 @@ func TestMessageStreamChunksFallsBackWhenUnsupported(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestMessageStreamFallbackDoesNotCompleteWithEmptyText(t *testing.T) {
|
||||
d := newDispatcher()
|
||||
body := `{"jsonrpc":"2.0","id":1,"method":"message/stream","params":{"message":{"role":"user","parts":[{"kind":"text","text":"ping"}],"kind":"message"}}}`
|
||||
req := httptest.NewRequest(http.MethodPost, "/", bytes.NewBufferString(body))
|
||||
rr := httptest.NewRecorder()
|
||||
|
||||
d.serveWithStream(rr, req, func(context.Context, string) (string, error) {
|
||||
return "", nil
|
||||
}, func(context.Context, string) (ai.Stream, error) {
|
||||
return nil, fmt.Errorf("%w: test provider", ai.ErrStreamingUnsupported)
|
||||
})
|
||||
|
||||
var event struct {
|
||||
Result Task `json:"result"`
|
||||
Error *rpcError `json:"error"`
|
||||
}
|
||||
for _, line := range strings.Split(strings.TrimSpace(rr.Body.String()), "\n") {
|
||||
line = strings.TrimSpace(strings.TrimPrefix(strings.TrimSpace(line), "data: "))
|
||||
if line == "" {
|
||||
continue
|
||||
}
|
||||
if err := json.Unmarshal([]byte(line), &event); err != nil {
|
||||
t.Fatalf("decode event %q: %v", line, err)
|
||||
}
|
||||
}
|
||||
if event.Error != nil {
|
||||
t.Fatalf("fallback event error: %+v", event.Error)
|
||||
}
|
||||
if event.Result.Status.State != stateFailed {
|
||||
t.Fatalf("fallback state = %q, want failed", event.Result.Status.State)
|
||||
}
|
||||
if got := textOf(event.Result.Artifacts[0].Parts); got == "" {
|
||||
t.Fatalf("fallback artifact text is empty: %+v", event.Result.Artifacts)
|
||||
}
|
||||
if got := textOf(event.Result.History[len(event.Result.History)-1].Parts); got == "" {
|
||||
t.Fatalf("fallback history text is empty: %+v", event.Result.History)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecodeAgentChatReplyFallsBackToProviderTextFields(t *testing.T) {
|
||||
for name, body := range map[string]string{
|
||||
"answer": `{"answer":"answer text"}`,
|
||||
"content": `{"content":"content text"}`,
|
||||
"text": `{"text":"text field"}`,
|
||||
"message_content": `{"message":{"content":"message content"}}`,
|
||||
"message_text": `{"message":{"text":"message text"}}`,
|
||||
} {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
got, err := decodeAgentChatReply([]byte(body))
|
||||
if err != nil {
|
||||
t.Fatalf("decodeAgentChatReply error: %v", err)
|
||||
}
|
||||
if strings.TrimSpace(got) == "" {
|
||||
t.Fatalf("decodeAgentChatReply(%s) returned empty text", body)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestTasksResubscribeStreamsCurrentAndSubsequentEvents(t *testing.T) {
|
||||
d := newDispatcher()
|
||||
initial := &Task{ID: "task-1", ContextID: "ctx-1", Kind: "task", Status: TaskStatus{State: stateWorking, Timestamp: time.Now().UTC().Format(time.RFC3339)}}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
module go-micro.dev/v6
|
||||
|
||||
go 1.24
|
||||
go 1.25.0
|
||||
|
||||
toolchain go1.24.1
|
||||
toolchain go1.25.12
|
||||
|
||||
require (
|
||||
dario.cat/mergo v1.0.2
|
||||
@@ -32,24 +32,23 @@ require (
|
||||
github.com/prometheus/client_model v0.6.1
|
||||
github.com/rabbitmq/amqp091-go v1.10.0
|
||||
github.com/stretchr/objx v0.5.2
|
||||
github.com/stretchr/testify v1.10.0
|
||||
github.com/stretchr/testify v1.11.1
|
||||
github.com/test-go/testify v1.1.4
|
||||
github.com/urfave/cli/v2 v2.27.6
|
||||
github.com/xlab/treeprint v1.2.0
|
||||
go.etcd.io/bbolt v1.4.0
|
||||
go.etcd.io/etcd/api/v3 v3.5.21
|
||||
go.etcd.io/etcd/client/v3 v3.5.21
|
||||
go.opentelemetry.io/otel v1.35.0
|
||||
go.opentelemetry.io/otel/sdk v1.35.0
|
||||
go.opentelemetry.io/otel/trace v1.35.0
|
||||
go.opentelemetry.io/otel v1.39.0
|
||||
go.opentelemetry.io/otel/sdk v1.39.0
|
||||
go.opentelemetry.io/otel/trace v1.39.0
|
||||
go.uber.org/zap v1.27.0
|
||||
golang.org/x/crypto v0.37.0
|
||||
golang.org/x/net v0.38.0
|
||||
golang.org/x/sync v0.13.0
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20250324211829-b45e905df463
|
||||
google.golang.org/grpc v1.71.1
|
||||
golang.org/x/crypto v0.51.0
|
||||
golang.org/x/net v0.55.0
|
||||
golang.org/x/sync v0.20.0
|
||||
google.golang.org/grpc v1.79.3
|
||||
google.golang.org/grpc/examples v0.0.0-20250515150734-f2d3e11f3057
|
||||
google.golang.org/protobuf v1.36.6
|
||||
google.golang.org/protobuf v1.36.10
|
||||
)
|
||||
|
||||
require (
|
||||
@@ -63,7 +62,7 @@ require (
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.5 // indirect
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
||||
github.com/fatih/color v1.16.0 // indirect
|
||||
github.com/go-logr/logr v1.4.2 // indirect
|
||||
github.com/go-logr/logr v1.4.3 // indirect
|
||||
github.com/go-logr/stdr v1.2.2 // indirect
|
||||
github.com/gogo/protobuf v1.3.2 // indirect
|
||||
github.com/google/go-tpm v0.9.3 // indirect
|
||||
@@ -97,19 +96,20 @@ require (
|
||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
|
||||
github.com/prometheus/common v0.63.0 // indirect
|
||||
github.com/prometheus/procfs v0.16.0 // indirect
|
||||
github.com/rogpeppe/go-internal v1.13.1 // indirect
|
||||
github.com/rogpeppe/go-internal v1.14.1 // indirect
|
||||
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
||||
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
|
||||
go.etcd.io/etcd/client/pkg/v3 v3.5.21 // indirect
|
||||
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
|
||||
go.opentelemetry.io/otel/metric v1.35.0 // indirect
|
||||
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
|
||||
go.opentelemetry.io/otel/metric v1.39.0 // indirect
|
||||
go.uber.org/multierr v1.10.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20250305212735-054e65f0b394 // indirect
|
||||
golang.org/x/mod v0.24.0 // indirect
|
||||
golang.org/x/sys v0.32.0 // indirect
|
||||
golang.org/x/text v0.24.0 // indirect
|
||||
golang.org/x/mod v0.35.0 // indirect
|
||||
golang.org/x/sys v0.45.0 // indirect
|
||||
golang.org/x/text v0.37.0 // indirect
|
||||
golang.org/x/time v0.11.0 // indirect
|
||||
golang.org/x/tools v0.31.0 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20250324211829-b45e905df463 // indirect
|
||||
golang.org/x/tools v0.44.0 // indirect
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20251202230838-ff82c1b0f217 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20251202230838-ff82c1b0f217 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
||||
@@ -65,8 +65,8 @@ github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9
|
||||
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
|
||||
github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
|
||||
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
|
||||
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||
github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
|
||||
github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
||||
github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI=
|
||||
@@ -317,8 +317,8 @@ github.com/rabbitmq/amqp091-go v1.10.0 h1:STpn5XsHlHGcecLmMFCtg7mqq0RnD+zFr4uzuk
|
||||
github.com/rabbitmq/amqp091-go v1.10.0/go.mod h1:Hy4jKW5kQART1u+JkDTF9YYOQUHXqMuhrgxOEeS7G4o=
|
||||
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
|
||||
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
|
||||
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
|
||||
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
|
||||
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
|
||||
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
|
||||
github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ=
|
||||
github.com/rs/zerolog v1.13.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OKkWU=
|
||||
github.com/rs/zerolog v1.15.0/go.mod h1:xYTKnLHcpfU2225ny5qZjxnj9NvkumZYjJHlAThCjNc=
|
||||
@@ -345,8 +345,8 @@ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P
|
||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
|
||||
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
||||
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
||||
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
||||
github.com/test-go/testify v1.1.4 h1:Tf9lntrKUMHiXQ07qBScBTSA0dhYQlu83hswqelv1iE=
|
||||
github.com/test-go/testify v1.1.4/go.mod h1:rH7cfJo/47vWGdi4GPj16x3/t1xGOj2YxzmNQzk2ghU=
|
||||
github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM=
|
||||
@@ -368,18 +368,18 @@ go.etcd.io/etcd/client/pkg/v3 v3.5.21 h1:lPBu71Y7osQmzlflM9OfeIV2JlmpBjqBNlLtcoB
|
||||
go.etcd.io/etcd/client/pkg/v3 v3.5.21/go.mod h1:BgqT/IXPjK9NkeSDjbzwsHySX3yIle2+ndz28nVsjUs=
|
||||
go.etcd.io/etcd/client/v3 v3.5.21 h1:T6b1Ow6fNjOLOtM0xSoKNQt1ASPCLWrF9XMHcH9pEyY=
|
||||
go.etcd.io/etcd/client/v3 v3.5.21/go.mod h1:mFYy67IOqmbRf/kRUvsHixzo3iG+1OF2W2+jVIQRAnU=
|
||||
go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=
|
||||
go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A=
|
||||
go.opentelemetry.io/otel v1.35.0 h1:xKWKPxrxB6OtMCbmMY021CqC45J+3Onta9MqjhnusiQ=
|
||||
go.opentelemetry.io/otel v1.35.0/go.mod h1:UEqy8Zp11hpkUrL73gSlELM0DupHoiq72dR+Zqel/+Y=
|
||||
go.opentelemetry.io/otel/metric v1.35.0 h1:0znxYu2SNyuMSQT4Y9WDWej0VpcsxkuklLa4/siN90M=
|
||||
go.opentelemetry.io/otel/metric v1.35.0/go.mod h1:nKVFgxBZ2fReX6IlyW28MgZojkoAkJGaE8CpgeAU3oE=
|
||||
go.opentelemetry.io/otel/sdk v1.35.0 h1:iPctf8iprVySXSKJffSS79eOjl9pvxV9ZqOWT0QejKY=
|
||||
go.opentelemetry.io/otel/sdk v1.35.0/go.mod h1:+ga1bZliga3DxJ3CQGg3updiaAJoNECOgJREo9KHGQg=
|
||||
go.opentelemetry.io/otel/sdk/metric v1.35.0 h1:1RriWBmCKgkeHEhM7a2uMjMUfP7MsOF5JpUCaEqEI9o=
|
||||
go.opentelemetry.io/otel/sdk/metric v1.35.0/go.mod h1:is6XYCUMpcKi+ZsOvfluY5YstFnhW0BidkR+gL+qN+w=
|
||||
go.opentelemetry.io/otel/trace v1.35.0 h1:dPpEfJu1sDIqruz7BHFG3c7528f6ddfSWfFDVt/xgMs=
|
||||
go.opentelemetry.io/otel/trace v1.35.0/go.mod h1:WUk7DtFp1Aw2MkvqGdwiXYDZZNvA/1J8o6xRXLrIkyc=
|
||||
go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64=
|
||||
go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y=
|
||||
go.opentelemetry.io/otel v1.39.0 h1:8yPrr/S0ND9QEfTfdP9V+SiwT4E0G7Y5MO7p85nis48=
|
||||
go.opentelemetry.io/otel v1.39.0/go.mod h1:kLlFTywNWrFyEdH0oj2xK0bFYZtHRYUdv1NklR/tgc8=
|
||||
go.opentelemetry.io/otel/metric v1.39.0 h1:d1UzonvEZriVfpNKEVmHXbdf909uGTOQjA0HF0Ls5Q0=
|
||||
go.opentelemetry.io/otel/metric v1.39.0/go.mod h1:jrZSWL33sD7bBxg1xjrqyDjnuzTUB0x1nBERXd7Ftcs=
|
||||
go.opentelemetry.io/otel/sdk v1.39.0 h1:nMLYcjVsvdui1B/4FRkwjzoRVsMK8uL/cj0OyhKzt18=
|
||||
go.opentelemetry.io/otel/sdk v1.39.0/go.mod h1:vDojkC4/jsTJsE+kh+LXYQlbL8CgrEcwmt1ENZszdJE=
|
||||
go.opentelemetry.io/otel/sdk/metric v1.39.0 h1:cXMVVFVgsIf2YL6QkRF4Urbr/aMInf+2WKg+sEJTtB8=
|
||||
go.opentelemetry.io/otel/sdk/metric v1.39.0/go.mod h1:xq9HEVH7qeX69/JnwEfp6fVq5wosJsY1mt4lLfYdVew=
|
||||
go.opentelemetry.io/otel/trace v1.39.0 h1:2d2vfpEDmCJ5zVYz7ijaJdOF59xLomrvj7bjt6/qCJI=
|
||||
go.opentelemetry.io/otel/trace v1.39.0/go.mod h1:88w4/PnZSazkGzz/w84VHpQafiU4EtqqlVdxWy+rNOA=
|
||||
go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
|
||||
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
|
||||
go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
|
||||
@@ -408,8 +408,8 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh
|
||||
golang.org/x/crypto v0.0.0-20201203163018-be400aefbc4c/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
|
||||
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.37.0 h1:kJNSjF/Xp7kU0iB2Z+9viTPMW4EqqsrywMXLJOOsXSE=
|
||||
golang.org/x/crypto v0.37.0/go.mod h1:vg+k43peMZ0pUMhYmVAWysMK35e6ioLh3wB8ZCAfbVc=
|
||||
golang.org/x/crypto v0.51.0 h1:IBPXwPfKxY7cWQZ38ZCIRPI50YLeevDLlLnyC5wRGTI=
|
||||
golang.org/x/crypto v0.51.0/go.mod h1:8AdwkbraGNABw2kOX6YFPs3WM22XqI4EXEd8g+x7Oc8=
|
||||
golang.org/x/exp v0.0.0-20250305212735-054e65f0b394 h1:nDVHiLt8aIbd/VzvPWN6kSOPE7+F/fNFDSXLVYkE/Iw=
|
||||
golang.org/x/exp v0.0.0-20250305212735-054e65f0b394/go.mod h1:sIifuuw/Yco/y6yb6+bDNfyeQ/MdPUy/hKEMYQV17cM=
|
||||
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
@@ -418,8 +418,8 @@ golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzB
|
||||
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.24.0 h1:ZfthKaKaT4NrhGVZHO1/WDTwGES4De8KtWO0SIbNJMU=
|
||||
golang.org/x/mod v0.24.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww=
|
||||
golang.org/x/mod v0.35.0 h1:Ww1D637e6Pg+Zb2KrWfHQUnH2dQRLBQyAtpr/haaJeM=
|
||||
golang.org/x/mod v0.35.0/go.mod h1:+GwiRhIInF8wPm+4AoT6L0FA1QWAad3OMdTRx4tFYlU=
|
||||
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
@@ -433,16 +433,16 @@ golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v
|
||||
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
|
||||
golang.org/x/net v0.0.0-20210410081132-afb366fc7cd1/go.mod h1:9tjilg8BloeKEkVJvy7fQ90B1CfIiPueXVOjqfkSzI8=
|
||||
golang.org/x/net v0.0.0-20210726213435-c6fcb2dbf985/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.38.0 h1:vRMAPTMaeGqVhG5QyLJHqNDwecKTomGeqbnfZyKlBI8=
|
||||
golang.org/x/net v0.38.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8=
|
||||
golang.org/x/net v0.55.0 h1:bcvxaJn3e1U6InsFWt1JUq1aSjnRxLzT2rtD2KfkDF8=
|
||||
golang.org/x/net v0.55.0/go.mod h1:L5U2KuzuOe1lY7Z+aWVIKK6qEeJXnXV9yzGA+WCHJww=
|
||||
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.13.0 h1:AauUjRAJ9OSnvULf/ARrrVywoJDy0YS2AwQ98I37610=
|
||||
golang.org/x/sync v0.13.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
|
||||
golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4=
|
||||
golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
|
||||
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
@@ -473,8 +473,8 @@ golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBc
|
||||
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20=
|
||||
golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
||||
golang.org/x/sys v0.45.0 h1:dO4czNzziLiiXplLQgBCEpCvXQ3dnkn0SdaZSYdQ+FY=
|
||||
golang.org/x/sys v0.45.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
|
||||
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
@@ -482,8 +482,8 @@ golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.24.0 h1:dd5Bzh4yt5KYA8f9CJHCP4FB4D51c2c6JvN37xJJkJ0=
|
||||
golang.org/x/text v0.24.0/go.mod h1:L8rBsPeo2pSS+xqN0d5u2ikmjtmoJbDBT1b7nHvFCdU=
|
||||
golang.org/x/text v0.37.0 h1:Cqjiwd9eSg8e0QAkyCaQTNHFIIzWtidPahFWR83rTrc=
|
||||
golang.org/x/text v0.37.0/go.mod h1:a5sjxXGs9hsn/AJVwuElvCAo9v8QYLzvavO5z2PiM38=
|
||||
golang.org/x/time v0.11.0 h1:/bpjEDfN9tkoN/ryeYHnv5hcMlc8ncjMcM4XBk5NWV0=
|
||||
golang.org/x/time v0.11.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
@@ -499,24 +499,26 @@ golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapK
|
||||
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
|
||||
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||
golang.org/x/tools v0.1.6-0.20210726203631-07bc1bf47fb2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
|
||||
golang.org/x/tools v0.31.0 h1:0EedkvKDbh+qistFTd0Bcwe/YLh4vHwWEkiI0toFIBU=
|
||||
golang.org/x/tools v0.31.0/go.mod h1:naFTU+Cev749tSJRXJlna0T3WxKvb1kWEx15xA4SdmQ=
|
||||
golang.org/x/tools v0.44.0 h1:UP4ajHPIcuMjT1GqzDWRlalUEoY+uzoZKnhOjbIPD2c=
|
||||
golang.org/x/tools v0.44.0/go.mod h1:KA0AfVErSdxRZIsOVipbv3rQhVXTnlU6UhKxHd1seDI=
|
||||
golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20250324211829-b45e905df463 h1:hE3bRWtU6uceqlh4fhrSnUyjKHMKB9KrTLLG+bc0ddM=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20250324211829-b45e905df463/go.mod h1:U90ffi8eUL9MwPcrJylN5+Mk2v3vuPDptd5yyNUiRR8=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20250324211829-b45e905df463 h1:e0AIkUUhxyBKh6ssZNrAMeqhA7RKUj42346d1y02i2g=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20250324211829-b45e905df463/go.mod h1:qQ0YXyHHx3XkvlzUtpXDkS29lDSafHMZBAZDc03LQ3A=
|
||||
google.golang.org/grpc v1.71.1 h1:ffsFWr7ygTUscGPI0KKK6TLrGz0476KUvvsbqWK0rPI=
|
||||
google.golang.org/grpc v1.71.1/go.mod h1:H0GRtasmQOh9LkFoCPDu3ZrwUtD1YGE+b2vYBYd/8Ec=
|
||||
gonum.org/v1/gonum v0.16.0 h1:5+ul4Swaf3ESvrOnidPp4GZbzf0mxVQpDCYUQE7OJfk=
|
||||
gonum.org/v1/gonum v0.16.0/go.mod h1:fef3am4MQ93R2HHpKnLk4/Tbh/s0+wqD5nfa6Pnwy4E=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20251202230838-ff82c1b0f217 h1:fCvbg86sFXwdrl5LgVcTEvNC+2txB5mgROGmRL5mrls=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20251202230838-ff82c1b0f217/go.mod h1:+rXWjjaukWZun3mLfjmVnQi18E1AsFbDN9QdJ5YXLto=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20251202230838-ff82c1b0f217 h1:gRkg/vSppuSQoDjxyiGfN4Upv/h/DQmIR10ZU8dh4Ww=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20251202230838-ff82c1b0f217/go.mod h1:7i2o+ce6H/6BluujYR+kqX3GKH+dChPTQU19wjRPiGk=
|
||||
google.golang.org/grpc v1.79.3 h1:sybAEdRIEtvcD68Gx7dmnwjZKlyfuc61Dyo9pGXXkKE=
|
||||
google.golang.org/grpc v1.79.3/go.mod h1:KmT0Kjez+0dde/v2j9vzwoAScgEPx/Bw1CYChhHLrHQ=
|
||||
google.golang.org/grpc/examples v0.0.0-20250515150734-f2d3e11f3057 h1:lPv+iqlAyiKMjbL3ivJlAASixPknLv806R6zaoE4PUM=
|
||||
google.golang.org/grpc/examples v0.0.0-20250515150734-f2d3e11f3057/go.mod h1:WPWnet+nYurNGpV0rVYHI1YuOJwVHeM3t8f76m410XM=
|
||||
google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY=
|
||||
google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY=
|
||||
google.golang.org/protobuf v1.36.10 h1:AYd7cD/uASjIL6Q9LiTjz8JLcrh/88q5UObnmY3aOOE=
|
||||
google.golang.org/protobuf v1.36.10/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
|
||||
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
|
||||
@@ -3,8 +3,11 @@
|
||||
`go test ./...` includes `TestAgentProviderConformanceMatrix`, a shared agent
|
||||
scenario that runs against every registered chat provider. The scenario asks an
|
||||
agent to call a deterministic local tool, verifies the tool receives `ai.RunInfo`,
|
||||
and checks the final response carries the conformance marker. A fake provider path
|
||||
runs on every machine without network access so CI always exercises the harness.
|
||||
and checks the final response carries the conformance marker. The live matrix
|
||||
includes MiniMax in the tool/guardrail path in addition to providers with
|
||||
streaming coverage, so every supported chat provider has at least one key-gated
|
||||
agent contract. A fake provider path runs on every machine without network
|
||||
access so CI always exercises the harness.
|
||||
|
||||
Live providers are opt-in to avoid flaky unauthenticated PR checks and accidental
|
||||
API spend. To run the live matrix, set `GO_MICRO_AGENT_CONFORMANCE_LIVE=1` plus the
|
||||
@@ -17,6 +20,7 @@ provider API keys you want to exercise:
|
||||
| Atlas Cloud | `ATLASCLOUD_API_KEY` | `GO_MICRO_CONFORMANCE_ATLASCLOUD_MODEL` |
|
||||
| Gemini | `GEMINI_API_KEY` | `GO_MICRO_CONFORMANCE_GEMINI_MODEL` |
|
||||
| Groq | `GROQ_API_KEY` | `GO_MICRO_CONFORMANCE_GROQ_MODEL` |
|
||||
| MiniMax | `MINIMAX_API_KEY` | `GO_MICRO_CONFORMANCE_MINIMAX_MODEL` |
|
||||
| Mistral | `MISTRAL_API_KEY` | `GO_MICRO_CONFORMANCE_MISTRAL_MODEL` |
|
||||
| Together | `TOGETHER_API_KEY` | `GO_MICRO_CONFORMANCE_TOGETHER_MODEL` |
|
||||
|
||||
|
||||
@@ -21,8 +21,8 @@ Actions instead of subagents. Each role is a workflow:
|
||||
|------|------------------------|--------------|
|
||||
| **Planner** | `loop-planner.yml` — *Loop: Planner* | Tracks live state, prioritizes the roadmap + an internal scan, and maintains the ranked queue in [`.github/loop/PRIORITIES.md`](../../.github/loop/PRIORITIES.md). Decides *what*. |
|
||||
| **Generator** | `loop-builder.yml` — *Loop: Builder (Generator)* | Builds the top open queue item as a single-concern PR (via Codex) and self-merges on green CI. Does the work. |
|
||||
| **Evaluator** | `harness.yml` — *Harness (E2E)*, plus the CI gate (`tests.yaml`, `lint.yaml`) | Grades every change: the mock harness + unit/lint on each push/PR, and real-model conformance hourly. A *separate* grader — never the generator judging itself. |
|
||||
| **Evaluator → feedback** | `loop-triage.yml` — *Loop: Triage (Evaluator feedback)* | When a gate workflow (Lint, Run Tests, or the harness) fails on a non-PR run, root-causes, dedupes, and files scoped fix issues back into the planner's queue. The hill-climbing feedback path. |
|
||||
| **Evaluator** | `harness.yml` — *Harness (E2E)*, plus the CI gate (`tests.yaml`, `lint.yaml`, `govulncheck.yml`) | Grades every change: the mock harness + unit/lint + reachable-CVE scan on each push/PR, and real-model conformance hourly. A *separate* grader — never the generator judging itself. |
|
||||
| **Evaluator → feedback** | `loop-triage.yml` — *Loop: Triage (Evaluator feedback)* | When a gate workflow (Lint, Run Tests, govulncheck, or the harness) fails on a non-PR run, root-causes, dedupes, and files scoped fix issues back into the planner's queue. The hill-climbing feedback path. |
|
||||
| **Coherence** | `loop-coherence.yml` — *Loop: Coherence* | Keeps README/website/docs/blog aligned with the North Star, keeps `CHANGELOG.md` living (reconciling `[Unreleased]` against merged PRs and rolling it into version headings as tags cut), and drafts the changelog blog post. |
|
||||
| **Security** | `loop-security.yml` — *Loop: Security* | Weekly vulnerability audit of the attack surface (MCP/A2A gateways, x402, auth, provider URLs, agent tool loop, deps via `govulncheck`). Files `security` issues; **never auto-merges** fixes and **never publishes exploit detail** in public issues (responsible disclosure); risky fixes are `needs-human`. |
|
||||
| **Release** | `loop-release.yml` — *Loop: Release (daily patch)* | Cuts a daily patch tag when master has new commits, so the *installable* framework tracks the loop's improvements (triggers `release.yml`/goreleaser). Minor/major bumps stay with the human. |
|
||||
|
||||
@@ -49,19 +49,31 @@ type CreateResponse struct {
|
||||
}
|
||||
|
||||
type WorkspaceService struct {
|
||||
mu sync.Mutex
|
||||
n int
|
||||
mu sync.Mutex
|
||||
n int
|
||||
byOwner map[string]*Workspace
|
||||
}
|
||||
|
||||
// Create provisions a workspace for a new user.
|
||||
// @example {"owner": "alice@acme.com"}
|
||||
func (s *WorkspaceService) Create(ctx context.Context, req *CreateRequest, rsp *CreateResponse) error {
|
||||
s.mu.Lock()
|
||||
if s.byOwner == nil {
|
||||
s.byOwner = make(map[string]*Workspace)
|
||||
}
|
||||
if ws, ok := s.byOwner[req.Owner]; ok {
|
||||
s.mu.Unlock()
|
||||
fmt.Printf(" \033[32m[workspace]\033[0m duplicate suppressed %s for %s\n", ws.ID, req.Owner)
|
||||
rsp.Workspace = ws
|
||||
return nil
|
||||
}
|
||||
s.n++
|
||||
id := fmt.Sprintf("ws-%d", s.n)
|
||||
ws := &Workspace{ID: id, Owner: req.Owner}
|
||||
s.byOwner[req.Owner] = ws
|
||||
s.mu.Unlock()
|
||||
fmt.Printf(" \033[32m[workspace]\033[0m created %s for %s\n", id, req.Owner)
|
||||
rsp.Workspace = &Workspace{ID: id, Owner: req.Owner}
|
||||
rsp.Workspace = ws
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -79,14 +91,26 @@ type SendResponse struct {
|
||||
Sent bool `json:"sent"`
|
||||
}
|
||||
type NotifyService struct {
|
||||
mu sync.Mutex
|
||||
n int
|
||||
mu sync.Mutex
|
||||
n int
|
||||
sent map[string]bool
|
||||
}
|
||||
|
||||
// Send delivers a notification message to a recipient.
|
||||
// @example {"to": "alice@acme.com", "message": "Welcome"}
|
||||
func (s *NotifyService) Send(ctx context.Context, req *SendRequest, rsp *SendResponse) error {
|
||||
key := strings.ToLower(strings.TrimSpace(req.To))
|
||||
s.mu.Lock()
|
||||
if s.sent == nil {
|
||||
s.sent = make(map[string]bool)
|
||||
}
|
||||
if s.sent[key] {
|
||||
s.mu.Unlock()
|
||||
fmt.Printf(" \033[35m[notify]\033[0m duplicate suppressed to=%s message=%q\n", req.To, req.Message)
|
||||
rsp.Sent = true
|
||||
return nil
|
||||
}
|
||||
s.sent[key] = true
|
||||
s.n++
|
||||
s.mu.Unlock()
|
||||
fmt.Printf(" \033[35m[notify]\033[0m 📨 to=%s message=%q\n", req.To, req.Message)
|
||||
@@ -178,6 +202,31 @@ func waitFor(reg registry.Registry, name string) {
|
||||
}
|
||||
}
|
||||
|
||||
func waitForOnboardingSideEffects(ctx context.Context, wsSvc *WorkspaceService, ntSvc *NotifyService, recoverMissingNotify func(context.Context) error) error {
|
||||
ticker := time.NewTicker(50 * time.Millisecond)
|
||||
defer ticker.Stop()
|
||||
|
||||
recovered := false
|
||||
for {
|
||||
workspaces, notifications := wsSvc.count(), ntSvc.count()
|
||||
if workspaces >= 1 && notifications >= 1 {
|
||||
return nil
|
||||
}
|
||||
if workspaces >= 1 && notifications == 0 && !recovered && recoverMissingNotify != nil {
|
||||
recovered = true
|
||||
if err := recoverMissingNotify(ctx); err != nil {
|
||||
return fmt.Errorf("agent-flow created workspace but failed to recover missing onboarding notification: workspaces=%d/1 notifications=%d/1: %w", workspaces, notifications, err)
|
||||
}
|
||||
}
|
||||
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return fmt.Errorf("agent-flow missing required onboarding side effects before timeout: workspaces=%d/1 notifications=%d/1", workspaces, notifications)
|
||||
case <-ticker.C:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
provider := flag.String("provider", "mock", "LLM provider: mock (default), anthropic, openai, ...")
|
||||
flag.Parse()
|
||||
@@ -257,20 +306,25 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Wait for the agent to finish acting.
|
||||
deadline := time.Now().Add(30 * time.Second)
|
||||
for time.Now().Before(deadline) {
|
||||
if ntSvc.count() >= 1 && wsSvc.count() >= 1 {
|
||||
break
|
||||
}
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
}
|
||||
// Wait for the agent to finish acting, and fail the harness if the
|
||||
// provider returns a successful reply without the required service side
|
||||
// effects. The 0→hero/provider conformance path must not print success
|
||||
// unless the services → agent → workflow contract actually happened.
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
err := waitForOnboardingSideEffects(ctx, wsSvc, ntSvc, func(ctx context.Context) error {
|
||||
fmt.Print("\n\033[33mwarning:\033[0m workspace exists before notify; retrying the welcome notification once before the flow can complete.\n")
|
||||
_, err := onboarder.Ask(ctx, "The workspace for alice@acme.com already exists. Send exactly one welcome notification to alice@acme.com now. Use the notify service. Do not create another workspace and do not answer until the notification tool call has succeeded.")
|
||||
return err
|
||||
})
|
||||
cancel()
|
||||
|
||||
fmt.Printf("\n\033[1mresult:\033[0m workspaces created=%d, notifications sent=%d\n", wsSvc.count(), ntSvc.count())
|
||||
if rs := f.Results(); len(rs) > 0 {
|
||||
fmt.Printf("flow reply: %s\n", rs[len(rs)-1].Reply)
|
||||
}
|
||||
if wsSvc.count() >= 1 && ntSvc.count() >= 1 {
|
||||
fmt.Println("\n\033[32m✓ the agent onboarded the user — triggered by an event, not a prompt\033[0m")
|
||||
if err != nil {
|
||||
fmt.Printf("\n\033[31m✗ %v\033[0m\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Println("\n\033[32m✓ the agent onboarded the user — triggered by an event, not a prompt\033[0m")
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -99,3 +101,111 @@ func TestEventTriggersAgentNoPrompt(t *testing.T) {
|
||||
t.Errorf("flow recorded no result for the event")
|
||||
}
|
||||
}
|
||||
|
||||
func TestWaitForOnboardingSideEffectsFailsWhenMissing(t *testing.T) {
|
||||
wsSvc := new(WorkspaceService)
|
||||
ntSvc := new(NotifyService)
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond)
|
||||
defer cancel()
|
||||
|
||||
err := waitForOnboardingSideEffects(ctx, wsSvc, ntSvc, nil)
|
||||
if err == nil {
|
||||
t.Fatal("waitForOnboardingSideEffects returned nil, want missing side effects error")
|
||||
}
|
||||
if got := err.Error(); !strings.Contains(got, "workspaces=0/1") || !strings.Contains(got, "notifications=0/1") {
|
||||
t.Fatalf("waitForOnboardingSideEffects error %q does not report missing side effects", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWaitForOnboardingSideEffectsPassesWhenComplete(t *testing.T) {
|
||||
wsSvc := new(WorkspaceService)
|
||||
ntSvc := new(NotifyService)
|
||||
|
||||
if err := wsSvc.Create(context.Background(), &CreateRequest{Owner: "alice@acme.com"}, &CreateResponse{}); err != nil {
|
||||
t.Fatalf("create workspace: %v", err)
|
||||
}
|
||||
if err := ntSvc.Send(context.Background(), &SendRequest{To: "alice@acme.com", Message: "Welcome"}, &SendResponse{}); err != nil {
|
||||
t.Fatalf("send notification: %v", err)
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
||||
defer cancel()
|
||||
if err := waitForOnboardingSideEffects(ctx, wsSvc, ntSvc, nil); err != nil {
|
||||
t.Fatalf("waitForOnboardingSideEffects returned %v, want nil", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWaitForOnboardingSideEffectsRecoversMissingNotification(t *testing.T) {
|
||||
wsSvc := new(WorkspaceService)
|
||||
ntSvc := new(NotifyService)
|
||||
|
||||
if err := wsSvc.Create(context.Background(), &CreateRequest{Owner: "alice@acme.com"}, &CreateResponse{}); err != nil {
|
||||
t.Fatalf("create workspace: %v", err)
|
||||
}
|
||||
|
||||
recovered := false
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
||||
defer cancel()
|
||||
err := waitForOnboardingSideEffects(ctx, wsSvc, ntSvc, func(ctx context.Context) error {
|
||||
recovered = true
|
||||
return ntSvc.Send(ctx, &SendRequest{To: "alice@acme.com", Message: "Welcome — your workspace is ready."}, &SendResponse{})
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("waitForOnboardingSideEffects returned %v, want recovered notification", err)
|
||||
}
|
||||
if !recovered {
|
||||
t.Fatal("missing notification recovery did not run")
|
||||
}
|
||||
if got := ntSvc.count(); got != 1 {
|
||||
t.Fatalf("notifications sent = %d, want 1 after recovery", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWorkspaceCreateSuppressesDuplicateOwner(t *testing.T) {
|
||||
wsSvc := new(WorkspaceService)
|
||||
first := new(CreateResponse)
|
||||
if err := wsSvc.Create(context.Background(), &CreateRequest{Owner: "alice@acme.com"}, first); err != nil {
|
||||
t.Fatalf("create first workspace: %v", err)
|
||||
}
|
||||
second := new(CreateResponse)
|
||||
if err := wsSvc.Create(context.Background(), &CreateRequest{Owner: "alice@acme.com"}, second); err != nil {
|
||||
t.Fatalf("create duplicate workspace: %v", err)
|
||||
}
|
||||
|
||||
if got := wsSvc.count(); got != 1 {
|
||||
t.Fatalf("workspace creations = %d, want 1 after duplicate owner replay", got)
|
||||
}
|
||||
if first.Workspace == nil || second.Workspace == nil || second.Workspace.ID != first.Workspace.ID {
|
||||
t.Fatalf("duplicate create returned workspace %#v, want original %#v", second.Workspace, first.Workspace)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNotifySendSuppressesDuplicateMessage(t *testing.T) {
|
||||
ntSvc := new(NotifyService)
|
||||
req := &SendRequest{To: "alice@acme.com", Message: "Welcome — your workspace is ready."}
|
||||
if err := ntSvc.Send(context.Background(), req, &SendResponse{}); err != nil {
|
||||
t.Fatalf("send first notification: %v", err)
|
||||
}
|
||||
if err := ntSvc.Send(context.Background(), req, &SendResponse{}); err != nil {
|
||||
t.Fatalf("send duplicate notification: %v", err)
|
||||
}
|
||||
|
||||
if got := ntSvc.count(); got != 1 {
|
||||
t.Fatalf("notifications sent = %d, want 1 after duplicate message replay", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNotifySendSuppressesDuplicateRecipient(t *testing.T) {
|
||||
ntSvc := new(NotifyService)
|
||||
if err := ntSvc.Send(context.Background(), &SendRequest{To: "Alice@Acme.com", Message: "Welcome — your workspace is ready."}, &SendResponse{}); err != nil {
|
||||
t.Fatalf("send first notification: %v", err)
|
||||
}
|
||||
if err := ntSvc.Send(context.Background(), &SendRequest{To: " alice@acme.com ", Message: "Your workspace is ready."}, &SendResponse{}); err != nil {
|
||||
t.Fatalf("send duplicate recipient notification: %v", err)
|
||||
}
|
||||
|
||||
if got := ntSvc.count(); got != 1 {
|
||||
t.Fatalf("notifications sent = %d, want 1 after duplicate recipient replay", got)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -187,13 +187,14 @@ func (s *NotifyService) duplicateAttempts() int {
|
||||
func notifyDedupKey(to, message string) string {
|
||||
recipient := canonicalLaunchNotifyRecipient(normalizeNotifyText(to))
|
||||
body := normalizeNotifyText(message)
|
||||
if isLaunchReadinessNotify(body) {
|
||||
if recipient == "owner@acme.com" && isLaunchReadinessNotify(body) {
|
||||
body = "launch-readiness"
|
||||
}
|
||||
return recipient + "\x00" + body
|
||||
}
|
||||
|
||||
func canonicalLaunchNotifyRecipient(recipient string) string {
|
||||
recipient = canonicalSpokenEmailRecipient(recipient)
|
||||
switch recipient {
|
||||
case "owner", "launch owner", "plan owner", "owner acme com", "owner@acme com", "owner @ acme com":
|
||||
return "owner@acme.com"
|
||||
@@ -205,6 +206,14 @@ func canonicalLaunchNotifyRecipient(recipient string) string {
|
||||
}
|
||||
}
|
||||
|
||||
func canonicalSpokenEmailRecipient(recipient string) string {
|
||||
fields := strings.Fields(recipient)
|
||||
if len(fields) == 5 && fields[1] == "at" && fields[3] == "dot" {
|
||||
return fields[0] + "@" + fields[2] + "." + fields[4]
|
||||
}
|
||||
return recipient
|
||||
}
|
||||
|
||||
func normalizeNotifyText(message string) string {
|
||||
message = strings.ToLower(strings.TrimSpace(message))
|
||||
message = strings.Map(func(r rune) rune {
|
||||
@@ -221,12 +230,18 @@ func normalizeNotifyText(message string) string {
|
||||
}
|
||||
|
||||
func isLaunchReadinessNotify(message string) bool {
|
||||
return strings.Contains(message, "launch") &&
|
||||
strings.Contains(message, "plan") &&
|
||||
(strings.Contains(message, "ready") ||
|
||||
strings.Contains(message, "readiness") ||
|
||||
strings.Contains(message, "prepared") ||
|
||||
strings.Contains(message, "complete"))
|
||||
hasLaunch := strings.Contains(message, "launch")
|
||||
hasPlanOrReadiness := strings.Contains(message, "plan") ||
|
||||
strings.Contains(message, "readiness") ||
|
||||
strings.Contains(message, "ready")
|
||||
hasCompletion := strings.Contains(message, "ready") ||
|
||||
strings.Contains(message, "readiness") ||
|
||||
strings.Contains(message, "prepared") ||
|
||||
strings.Contains(message, "complete") ||
|
||||
strings.Contains(message, "finished") ||
|
||||
strings.Contains(message, "done") ||
|
||||
strings.Contains(message, "sent")
|
||||
return hasLaunch && hasPlanOrReadiness && hasCompletion
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -424,14 +439,20 @@ func runPlanDelegate(provider string) error {
|
||||
if err := task.Handle(taskSvc); err != nil {
|
||||
return fmt.Errorf("task handle: %w", err)
|
||||
}
|
||||
go task.Run()
|
||||
if err := task.Start(); err != nil {
|
||||
return fmt.Errorf("task start: %w", err)
|
||||
}
|
||||
defer task.Stop()
|
||||
|
||||
notifySvc := new(NotifyService)
|
||||
notify := service.New(service.Name("notify"), service.Address("127.0.0.1:0"), service.Registry(reg), service.Client(cl))
|
||||
if err := notify.Handle(notifySvc); err != nil {
|
||||
return fmt.Errorf("notify handle: %w", err)
|
||||
}
|
||||
go notify.Run()
|
||||
if err := notify.Start(); err != nil {
|
||||
return fmt.Errorf("notify start: %w", err)
|
||||
}
|
||||
defer notify.Stop()
|
||||
|
||||
// Real comms agent (owns notify), registered so delegate reaches it over RPC.
|
||||
commsOpts := []agent.Option{
|
||||
@@ -482,7 +503,7 @@ func runPlanDelegate(provider string) error {
|
||||
|
||||
f := flow.New("zero-to-hero",
|
||||
flow.Steps(
|
||||
flow.Step{Name: "conductor", Run: planDelegateConductorStep(conductor)},
|
||||
flow.Step{Name: "conductor", Run: planDelegateConductorStep(conductor, taskSvc, notifySvc)},
|
||||
flow.Step{Name: "require-notify", Run: requireDelegatedNotifyStep(taskSvc, notifySvc, func(ctx context.Context) error {
|
||||
_, err := comms.Ask(ctx, "Send exactly one owner readiness notification now with this exact task: "+delegatedNotifyTask+" Use the notify service and do not answer until the notification has been sent.")
|
||||
return err
|
||||
@@ -503,17 +524,17 @@ func runPlanDelegate(provider string) error {
|
||||
executeDone <- f.Execute(ctx, "launch readiness")
|
||||
}()
|
||||
|
||||
if err := waitForPlanDelegateExecution(executeDone, taskSvc, notifySvc); err != nil {
|
||||
if err := waitForPlanDelegateExecution(executeDone, taskSvc, notifySvc, func(ctx context.Context) error {
|
||||
_, err := comms.Ask(ctx, "Recover the missing owner readiness notification now for the launch work already created. Send exactly one notification with this exact task: "+delegatedNotifyTask+" Use the notify service and do not create or modify tasks.")
|
||||
return err
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Prove plan was persisted to the real store.
|
||||
if recs, _ := store.Scope(mem, "agent", "conductor").Read("plan"); len(recs) > 0 {
|
||||
fmt.Printf("\n\033[1mstored plan (agent/conductor/plan):\033[0m %s\n", string(recs[0].Value))
|
||||
} else {
|
||||
return fmt.Errorf("plan was not persisted")
|
||||
if err := requireConductorPlan(context.Background(), mem, conductor); err != nil {
|
||||
return err
|
||||
}
|
||||
if taskSvc.count() != 3 || notifySvc.count() != 1 {
|
||||
if taskSvc.count() == 0 || notifySvc.count() != 1 {
|
||||
return fmt.Errorf("unexpected side effects: tasks=%d notify=%d", taskSvc.count(), notifySvc.count())
|
||||
}
|
||||
|
||||
@@ -521,20 +542,68 @@ func runPlanDelegate(provider string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func planDelegateConductorStep(conductor agent.Agent) flow.StepFunc {
|
||||
func requireConductorPlan(ctx context.Context, mem store.Store, conductor agent.Agent) error {
|
||||
recs, _ := store.Scope(mem, "agent", "conductor").Read("plan")
|
||||
if len(recs) == 0 && conductor != nil {
|
||||
fmt.Print("\n\033[33mwarning:\033[0m conductor completed side effects without a persisted plan; retrying plan persistence once before final assertions.\n")
|
||||
_, err := conductor.Ask(ctx, "Persist the launch-readiness plan now using the built-in plan tool before answering. Record exactly these completed steps: Design launch task, Build launch task, Ship launch task, and delegate owner readiness notification to comms. Do not call task or notify tools.")
|
||||
if err != nil {
|
||||
return fmt.Errorf("plan was not persisted at agent/conductor/plan and recovery prompt failed after completed side effects: %w", err)
|
||||
}
|
||||
recs, _ = store.Scope(mem, "agent", "conductor").Read("plan")
|
||||
}
|
||||
if len(recs) == 0 {
|
||||
return fmt.Errorf("plan was not persisted at agent/conductor/plan; conductor completed task/notify side effects without calling the built-in plan tool")
|
||||
}
|
||||
if len(recs) != 1 {
|
||||
return fmt.Errorf("unexpected persisted conductor plans at agent/conductor/plan: got %d records, want 1", len(recs))
|
||||
}
|
||||
fmt.Printf("\n\033[1mstored plan (agent/conductor/plan):\033[0m %s\n", string(recs[0].Value))
|
||||
return nil
|
||||
}
|
||||
|
||||
func planDelegateConductorStep(conductor agent.Agent, taskSvc *TaskService, notifySvc *NotifyService) flow.StepFunc {
|
||||
return func(ctx context.Context, in flow.State) (flow.State, error) {
|
||||
prompt := "Create three launch tasks (Design, Build, Ship), then make sure owner@acme.com is notified: " + in.String()
|
||||
rsp, err := conductor.Ask(ctx, prompt)
|
||||
if err != nil {
|
||||
if isUnfinishedPlanError(err) && taskSvc != nil && notifySvc != nil && taskSvc.count() > 0 && notifySvc.count() == 0 {
|
||||
fmt.Printf("\n\033[33mwarning:\033[0m conductor stopped with unfinished delegation after creating tasks; continuing to require-notify recovery: %v\n", err)
|
||||
return in, nil
|
||||
}
|
||||
return in, err
|
||||
}
|
||||
if rsp != nil && rsp.Reply != "" {
|
||||
fmt.Println("\n\033[1m< conductor reply:\033[0m", rsp.Reply)
|
||||
}
|
||||
if taskSvc != nil && notifySvc != nil && taskSvc.count() == 0 && notifySvc.count() == 0 {
|
||||
fmt.Print("\n\033[33mwarning:\033[0m conductor persisted/planned without service side effects; retrying task execution before notify gate.\n")
|
||||
rsp, err = conductor.Ask(ctx, "Continue the launch-readiness run now. Execute the persisted plan by calling the task Add tool exactly once for Design, Build, and Ship, then delegate the owner readiness notification to comms. Do not answer until at least one required tool call succeeds.")
|
||||
if err != nil {
|
||||
if isUnfinishedPlanError(err) && taskSvc.count() > 0 && notifySvc.count() == 0 {
|
||||
fmt.Printf("\n\033[33mwarning:\033[0m conductor recovered tasks but stopped before notification; continuing to require-notify recovery: %v\n", err)
|
||||
return in, nil
|
||||
}
|
||||
return in, err
|
||||
}
|
||||
if rsp != nil && rsp.Reply != "" {
|
||||
fmt.Println("\n\033[1m< conductor reply:\033[0m", rsp.Reply)
|
||||
}
|
||||
}
|
||||
if taskSvc != nil && notifySvc != nil && taskSvc.count() == 0 {
|
||||
return in, fmt.Errorf("plan-delegate reached notify gate before task side effects completed (tasks=0/3 notify=%d/1); model produced a plan but did not call task Add for Design, Build, and Ship", notifySvc.count())
|
||||
}
|
||||
return in, nil
|
||||
}
|
||||
}
|
||||
|
||||
func isUnfinishedPlanError(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
return strings.Contains(strings.ToLower(err.Error()), "unfinished plan steps")
|
||||
}
|
||||
|
||||
func requireDelegatedNotifyStep(taskSvc *TaskService, notifySvc *NotifyService, recoverMissingNotify func(context.Context) error) flow.StepFunc {
|
||||
return func(ctx context.Context, in flow.State) (flow.State, error) {
|
||||
tasks := taskSvc.count()
|
||||
@@ -542,7 +611,7 @@ func requireDelegatedNotifyStep(taskSvc *TaskService, notifySvc *NotifyService,
|
||||
if notify == 1 {
|
||||
return in, nil
|
||||
}
|
||||
if recoverMissingNotify == nil || tasks != 3 || notify != 0 {
|
||||
if recoverMissingNotify == nil || tasks == 0 || notify != 0 {
|
||||
return in, fmt.Errorf("delegation completed without required notify side effect: notify=%d, want 1", notify)
|
||||
}
|
||||
settled, err := waitForNotifySideEffect(notifySvc, delegatedNotifySettleTimeout)
|
||||
@@ -569,7 +638,7 @@ func requireDelegatedNotifyStep(taskSvc *TaskService, notifySvc *NotifyService,
|
||||
}
|
||||
}
|
||||
|
||||
func waitForPlanDelegateExecution(done <-chan error, taskSvc *TaskService, notifySvc *NotifyService) error {
|
||||
func waitForPlanDelegateExecution(done <-chan error, taskSvc *TaskService, notifySvc *NotifyService, recoverMissingNotify func(context.Context) error) error {
|
||||
ticker := time.NewTicker(50 * time.Millisecond)
|
||||
defer ticker.Stop()
|
||||
for {
|
||||
@@ -578,12 +647,26 @@ func waitForPlanDelegateExecution(done <-chan error, taskSvc *TaskService, notif
|
||||
tasks := taskSvc.count()
|
||||
notify := notifySvc.count()
|
||||
if err != nil {
|
||||
if hasCompletedPlanDelegateSideEffects(tasks, notify) {
|
||||
fmt.Printf("\n\033[33mwarning:\033[0m flow execute returned after completed side effects: %v\n", err)
|
||||
return nil
|
||||
}
|
||||
if isClientTimeout(err) {
|
||||
if tasks == 3 && notify == 1 {
|
||||
fmt.Printf("\n\033[33mwarning:\033[0m flow execute returned after completed side effects: %v\n", err)
|
||||
return classifiedPlanDelegateTimeout(tasks, notify, err)
|
||||
}
|
||||
if isUnfinishedPlanError(err) && tasks > 0 && notify == 0 && recoverMissingNotify != nil {
|
||||
fmt.Printf("\n\033[33mwarning:\033[0m flow stopped after partial plan side effects; recovering missing delegated notify: %v\n", err)
|
||||
if recoverErr := recoverMissingNotify(context.Background()); recoverErr != nil {
|
||||
return fmt.Errorf("flow execute after side effects tasks=%d notify=%d and recovery failed: %w", tasks, notify, recoverErr)
|
||||
}
|
||||
settled, waitErr := waitForNotifySideEffect(notifySvc, delegatedNotifySettleTimeout)
|
||||
if waitErr != nil {
|
||||
return waitErr
|
||||
}
|
||||
if settled {
|
||||
return nil
|
||||
}
|
||||
return classifiedPlanDelegateTimeout(tasks, notify, err)
|
||||
return fmt.Errorf("flow execute after side effects tasks=%d notify=%d: delegation recovery completed without required notify side effect: notify=%d, want 1", tasks, notify, notifySvc.count())
|
||||
}
|
||||
return fmt.Errorf("flow execute after side effects tasks=%d notify=%d: %w", tasks, notify, err)
|
||||
}
|
||||
@@ -612,6 +695,10 @@ func waitForNotifySideEffect(notifySvc *NotifyService, timeout time.Duration) (b
|
||||
}
|
||||
}
|
||||
|
||||
func hasCompletedPlanDelegateSideEffects(tasks, notify int) bool {
|
||||
return tasks == 3 && notify == 1
|
||||
}
|
||||
|
||||
func classifiedPlanDelegateTimeout(tasks, notify int, err error) error {
|
||||
return fmt.Errorf("provider latency/outage during plan-delegate before required side effects completed (tasks=%d/3 notify=%d/1); retry live provider or inspect provider logs if this recurs: %w", tasks, notify, err)
|
||||
}
|
||||
|
||||
@@ -53,14 +53,20 @@ func TestPlanDelegateEndToEnd(t *testing.T) {
|
||||
if err := task.Handle(taskSvc); err != nil {
|
||||
t.Fatalf("handle task: %v", err)
|
||||
}
|
||||
go task.Run()
|
||||
if err := task.Start(); err != nil {
|
||||
t.Fatalf("start task: %v", err)
|
||||
}
|
||||
defer task.Stop()
|
||||
|
||||
notifySvc := new(NotifyService)
|
||||
notify := service.New(service.Name("notify"), service.Address("127.0.0.1:0"), service.Registry(reg), service.Client(cl))
|
||||
if err := notify.Handle(notifySvc); err != nil {
|
||||
t.Fatalf("handle notify: %v", err)
|
||||
}
|
||||
go notify.Run()
|
||||
if err := notify.Start(); err != nil {
|
||||
t.Fatalf("start notify: %v", err)
|
||||
}
|
||||
defer notify.Stop()
|
||||
|
||||
// Real comms agent (owns notify), registered so delegate reaches it over RPC.
|
||||
comms := agent.New(
|
||||
@@ -136,14 +142,20 @@ func TestFlowDispatchesToAgentEndToEnd(t *testing.T) {
|
||||
if err := task.Handle(taskSvc); err != nil {
|
||||
t.Fatalf("handle task: %v", err)
|
||||
}
|
||||
go task.Run()
|
||||
if err := task.Start(); err != nil {
|
||||
t.Fatalf("start task: %v", err)
|
||||
}
|
||||
defer task.Stop()
|
||||
|
||||
notifySvc := new(NotifyService)
|
||||
notify := service.New(service.Name("notify"), service.Address("127.0.0.1:0"), service.Registry(reg), service.Client(cl))
|
||||
if err := notify.Handle(notifySvc); err != nil {
|
||||
t.Fatalf("handle notify: %v", err)
|
||||
}
|
||||
go notify.Run()
|
||||
if err := notify.Start(); err != nil {
|
||||
t.Fatalf("start notify: %v", err)
|
||||
}
|
||||
defer notify.Stop()
|
||||
|
||||
comms := agent.New(
|
||||
agent.Name("comms"),
|
||||
@@ -249,6 +261,30 @@ func TestPlanDelegateIdempotentDuplicateDelegateReplay(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestNotifyServiceDeduplicatesAtlasCloudLaunchReadinessParaphrases(t *testing.T) {
|
||||
svc := new(NotifyService)
|
||||
variants := []SendRequest{
|
||||
{To: "owner at acme dot com", Message: "The launch plan is ready."},
|
||||
{To: "launch owner", Message: "Launch readiness is complete."},
|
||||
{To: "Owner <owner@acme.com>", Message: "The launch plan is finished and the readiness notification was sent."},
|
||||
}
|
||||
for _, req := range variants {
|
||||
var rsp SendResponse
|
||||
if err := svc.Send(context.Background(), &req, &rsp); err != nil {
|
||||
t.Fatalf("Send(%+v): %v", req, err)
|
||||
}
|
||||
if !rsp.Sent {
|
||||
t.Fatalf("Send(%+v) returned sent=false", req)
|
||||
}
|
||||
}
|
||||
if got := svc.count(); got != 1 {
|
||||
t.Fatalf("notify side effects = %d, want 1 for launch-readiness paraphrase replays", got)
|
||||
}
|
||||
if got := svc.duplicateAttempts(); got != len(variants)-1 {
|
||||
t.Fatalf("duplicate attempts = %d, want %d", got, len(variants)-1)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTaskServiceAddIsIdempotentForLaunchTitles(t *testing.T) {
|
||||
svc := new(TaskService)
|
||||
for _, title := range []string{"Design", "design task", "Build", "Build launch task", "Ship", "ship readiness"} {
|
||||
@@ -276,7 +312,7 @@ func TestPlanDelegateExecutionAcceptsDuplicateNotifyReplay(t *testing.T) {
|
||||
|
||||
done := make(chan error, 1)
|
||||
done <- nil
|
||||
if err := waitForPlanDelegateExecution(done, new(TaskService), notifySvc); err != nil {
|
||||
if err := waitForPlanDelegateExecution(done, new(TaskService), notifySvc, nil); err != nil {
|
||||
t.Fatalf("waitForPlanDelegateExecution returned %v, want duplicate replay accepted", err)
|
||||
}
|
||||
if got := notifySvc.count(); got != 1 {
|
||||
@@ -287,12 +323,42 @@ func TestPlanDelegateExecutionAcceptsDuplicateNotifyReplay(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPlanDelegateExecutionRecoversUnfinishedPlanAfterPartialTaskSideEffect(t *testing.T) {
|
||||
taskSvc := new(TaskService)
|
||||
var addRsp AddResponse
|
||||
if err := taskSvc.Add(context.Background(), &AddRequest{Title: "Design"}, &addRsp); err != nil {
|
||||
t.Fatalf("Add: %v", err)
|
||||
}
|
||||
notifySvc := new(NotifyService)
|
||||
done := make(chan error, 1)
|
||||
done <- errors.New("agent run abc has unfinished plan steps: Delegate readiness notification to comms agent")
|
||||
|
||||
recovered := false
|
||||
err := waitForPlanDelegateExecution(done, taskSvc, notifySvc, func(ctx context.Context) error {
|
||||
recovered = true
|
||||
var sendRsp SendResponse
|
||||
return notifySvc.Send(ctx, &SendRequest{To: "owner@acme.com", Message: "The launch plan is ready"}, &sendRsp)
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("waitForPlanDelegateExecution returned %v, want partial notify recovery", err)
|
||||
}
|
||||
if !recovered {
|
||||
t.Fatal("missing notify recovery did not run")
|
||||
}
|
||||
if got := taskSvc.count(); got != 1 {
|
||||
t.Fatalf("task count = %d, want completed partial task to stay singular", got)
|
||||
}
|
||||
if got := notifySvc.count(); got != 1 {
|
||||
t.Fatalf("notify count = %d, want recovered notify side effect", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPlanDelegateExecutionRejectsClaimedCompletionWithoutNotify(t *testing.T) {
|
||||
notifySvc := new(NotifyService)
|
||||
done := make(chan error, 1)
|
||||
done <- nil
|
||||
|
||||
err := waitForPlanDelegateExecution(done, new(TaskService), notifySvc)
|
||||
err := waitForPlanDelegateExecution(done, new(TaskService), notifySvc, nil)
|
||||
if err == nil {
|
||||
t.Fatal("waitForPlanDelegateExecution returned nil, want missing notify side-effect error")
|
||||
}
|
||||
@@ -301,6 +367,158 @@ func TestPlanDelegateExecutionRejectsClaimedCompletionWithoutNotify(t *testing.T
|
||||
}
|
||||
}
|
||||
|
||||
type scriptedAgent struct {
|
||||
replies []func(context.Context, string) (*agent.Response, error)
|
||||
calls int
|
||||
}
|
||||
|
||||
func (a *scriptedAgent) Name() string { return "scripted" }
|
||||
func (a *scriptedAgent) Init(...agent.Option) {}
|
||||
func (a *scriptedAgent) Options() agent.Options { return agent.Options{} }
|
||||
func (a *scriptedAgent) Stream(context.Context, string) (ai.Stream, error) { return nil, nil }
|
||||
func (a *scriptedAgent) Run() error { return nil }
|
||||
func (a *scriptedAgent) Stop() error { return nil }
|
||||
func (a *scriptedAgent) String() string { return "scripted" }
|
||||
func (a *scriptedAgent) Ask(ctx context.Context, prompt string) (*agent.Response, error) {
|
||||
if a.calls >= len(a.replies) {
|
||||
return &agent.Response{Reply: "done"}, nil
|
||||
}
|
||||
reply := a.replies[a.calls]
|
||||
a.calls++
|
||||
return reply(ctx, prompt)
|
||||
}
|
||||
|
||||
type failingAgent struct {
|
||||
err error
|
||||
}
|
||||
|
||||
func (a failingAgent) Name() string { return "failing" }
|
||||
func (a failingAgent) Init(...agent.Option) {}
|
||||
func (a failingAgent) Options() agent.Options { return agent.Options{} }
|
||||
func (a failingAgent) Ask(context.Context, string) (*agent.Response, error) { return nil, a.err }
|
||||
func (a failingAgent) Stream(context.Context, string) (ai.Stream, error) { return nil, a.err }
|
||||
func (a failingAgent) Run() error { return nil }
|
||||
func (a failingAgent) Stop() error { return nil }
|
||||
func (a failingAgent) String() string { return "failing" }
|
||||
|
||||
func TestRequireConductorPlanRecoversAfterCompletedSideEffects(t *testing.T) {
|
||||
mem := store.NewMemoryStore()
|
||||
ag := &scriptedAgent{replies: []func(context.Context, string) (*agent.Response, error){
|
||||
func(ctx context.Context, prompt string) (*agent.Response, error) {
|
||||
if !strings.Contains(prompt, "built-in plan tool") || !strings.Contains(prompt, "Do not call task or notify tools") {
|
||||
return nil, errors.New("missing scoped plan recovery prompt")
|
||||
}
|
||||
if err := store.Scope(mem, "agent", "conductor").Write(&store.Record{Key: "plan", Value: []byte(`{"steps":[{"task":"Design launch task","status":"done"}]}`)}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &agent.Response{Reply: "Plan persisted."}, nil
|
||||
},
|
||||
}}
|
||||
|
||||
if err := requireConductorPlan(context.Background(), mem, ag); err != nil {
|
||||
t.Fatalf("requireConductorPlan returned %v, want recovered plan", err)
|
||||
}
|
||||
if ag.calls != 1 {
|
||||
t.Fatalf("conductor calls = %d, want one plan recovery prompt", ag.calls)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRequireConductorPlanFailureNamesScopedRecord(t *testing.T) {
|
||||
err := requireConductorPlan(context.Background(), store.NewMemoryStore(), &scriptedAgent{replies: []func(context.Context, string) (*agent.Response, error){
|
||||
func(context.Context, string) (*agent.Response, error) {
|
||||
return &agent.Response{Reply: "Done without plan."}, nil
|
||||
},
|
||||
}})
|
||||
if err == nil {
|
||||
t.Fatal("requireConductorPlan returned nil, want missing plan diagnostic")
|
||||
}
|
||||
for _, want := range []string{"agent/conductor/plan", "without calling the built-in plan tool"} {
|
||||
if got := err.Error(); !strings.Contains(got, want) {
|
||||
t.Fatalf("error = %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestPlanDelegateConductorRetriesAfterPlanOnlySuccess(t *testing.T) {
|
||||
taskSvc := new(TaskService)
|
||||
notifySvc := new(NotifyService)
|
||||
ag := &scriptedAgent{replies: []func(context.Context, string) (*agent.Response, error){
|
||||
func(context.Context, string) (*agent.Response, error) {
|
||||
return &agent.Response{Reply: "Plan saved."}, nil
|
||||
},
|
||||
func(ctx context.Context, prompt string) (*agent.Response, error) {
|
||||
if !strings.Contains(prompt, "Execute the persisted plan") {
|
||||
return nil, errors.New("missing explicit side-effect recovery prompt")
|
||||
}
|
||||
for _, title := range []string{"Design", "Build", "Ship"} {
|
||||
var rsp AddResponse
|
||||
if err := taskSvc.Add(ctx, &AddRequest{Title: title}, &rsp); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return &agent.Response{Reply: "Tasks created."}, nil
|
||||
},
|
||||
}}
|
||||
|
||||
step := planDelegateConductorStep(ag, taskSvc, notifySvc)
|
||||
if _, err := step(context.Background(), flow.State{}); err != nil {
|
||||
t.Fatalf("planDelegateConductorStep returned %v, want plan-only retry success", err)
|
||||
}
|
||||
if ag.calls != 2 {
|
||||
t.Fatalf("conductor calls = %d, want initial plan-only call plus one side-effect retry", ag.calls)
|
||||
}
|
||||
if got := taskSvc.count(); got != 3 {
|
||||
t.Fatalf("task count = %d, want recovered Design/Build/Ship side effects", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPlanDelegateConductorFailsBeforeNotifyGateAfterPlanOnlyRetryMiss(t *testing.T) {
|
||||
step := planDelegateConductorStep(&scriptedAgent{replies: []func(context.Context, string) (*agent.Response, error){
|
||||
func(context.Context, string) (*agent.Response, error) {
|
||||
return &agent.Response{Reply: "Plan saved."}, nil
|
||||
},
|
||||
func(context.Context, string) (*agent.Response, error) {
|
||||
return &agent.Response{Reply: "Still planning."}, nil
|
||||
},
|
||||
}}, new(TaskService), new(NotifyService))
|
||||
|
||||
_, err := step(context.Background(), flow.State{})
|
||||
if err == nil {
|
||||
t.Fatal("planDelegateConductorStep returned nil, want pre-notify-gate task side-effect error")
|
||||
}
|
||||
for _, want := range []string{"before task side effects completed", "tasks=0/3", "task Add for Design, Build, and Ship"} {
|
||||
if got := err.Error(); !strings.Contains(got, want) {
|
||||
t.Fatalf("error = %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestPlanDelegateConductorAllowsNotifyRecoveryAfterUnfinishedDelegation(t *testing.T) {
|
||||
taskSvc := new(TaskService)
|
||||
for _, title := range []string{"Design", "Build", "Ship"} {
|
||||
var rsp AddResponse
|
||||
if err := taskSvc.Add(context.Background(), &AddRequest{Title: title}, &rsp); err != nil {
|
||||
t.Fatalf("Add(%q): %v", title, err)
|
||||
}
|
||||
}
|
||||
notifySvc := new(NotifyService)
|
||||
step := planDelegateConductorStep(failingAgent{err: errors.New("agent run abc has unfinished plan steps: Delegate readiness notification to comms agent")}, taskSvc, notifySvc)
|
||||
if _, err := step(context.Background(), flow.State{}); err != nil {
|
||||
t.Fatalf("planDelegateConductorStep returned %v, want require-notify recovery to run", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPlanDelegateConductorKeepsUnfinishedTaskFailureActionable(t *testing.T) {
|
||||
step := planDelegateConductorStep(failingAgent{err: errors.New("agent run abc has unfinished plan steps: Create Build task")}, new(TaskService), new(NotifyService))
|
||||
err := func() error { _, err := step(context.Background(), flow.State{}); return err }()
|
||||
if err == nil {
|
||||
t.Fatal("planDelegateConductorStep returned nil, want unfinished task error")
|
||||
}
|
||||
if got := err.Error(); !strings.Contains(got, "Create Build task") {
|
||||
t.Fatalf("error = %q, want original unfinished task detail", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPlanDelegateExecutionRecoversMissingNotifyOnce(t *testing.T) {
|
||||
taskSvc := new(TaskService)
|
||||
for _, title := range []string{"Design", "Build", "Ship"} {
|
||||
@@ -415,16 +633,38 @@ func TestPlanDelegateExecutionAcceptsClientTimeoutAfterSideEffects(t *testing.T)
|
||||
done := make(chan error, 1)
|
||||
done <- errors.New(`{"id":"go.micro.client","code":408,"detail":"<nil>","status":"Request Timeout"}`)
|
||||
|
||||
if err := waitForPlanDelegateExecution(done, taskSvc, notifySvc); err != nil {
|
||||
if err := waitForPlanDelegateExecution(done, taskSvc, notifySvc, nil); err != nil {
|
||||
t.Fatalf("waitForPlanDelegateExecution returned %v, want completed side effects to satisfy client timeout", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPlanDelegateExecutionAcceptsApprovalPauseAfterSideEffects(t *testing.T) {
|
||||
taskSvc := new(TaskService)
|
||||
for _, title := range []string{"Design", "Build", "Ship"} {
|
||||
var rsp AddResponse
|
||||
if err := taskSvc.Add(context.Background(), &AddRequest{Title: title}, &rsp); err != nil {
|
||||
t.Fatalf("Add(%q): %v", title, err)
|
||||
}
|
||||
}
|
||||
notifySvc := new(NotifyService)
|
||||
var rsp SendResponse
|
||||
if err := notifySvc.Send(context.Background(), &SendRequest{To: "owner@acme.com", Message: "The launch plan is ready"}, &rsp); err != nil {
|
||||
t.Fatalf("Send: %v", err)
|
||||
}
|
||||
|
||||
done := make(chan error, 1)
|
||||
done <- errors.New("agent run abc paused for approval: The comms agent is repeatedly timing out (408 errors) while retrying the launch-readiness notification")
|
||||
|
||||
if err := waitForPlanDelegateExecution(done, taskSvc, notifySvc, nil); err != nil {
|
||||
t.Fatalf("waitForPlanDelegateExecution returned %v, want completed side effects to satisfy approval pause", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPlanDelegateExecutionClassifiesClientTimeoutBeforeSideEffects(t *testing.T) {
|
||||
done := make(chan error, 1)
|
||||
done <- errors.New(`{"id":"go.micro.client","code":408,"detail":"<nil>","status":"Request Timeout"}`)
|
||||
|
||||
err := waitForPlanDelegateExecution(done, new(TaskService), new(NotifyService))
|
||||
err := waitForPlanDelegateExecution(done, new(TaskService), new(NotifyService), nil)
|
||||
if err == nil {
|
||||
t.Fatal("waitForPlanDelegateExecution returned nil, want timeout before side effects to fail")
|
||||
}
|
||||
@@ -451,7 +691,7 @@ func TestPlanDelegateExecutionClassifiesPartialClientTimeout(t *testing.T) {
|
||||
done := make(chan error, 1)
|
||||
done <- errors.New(`{"id":"go.micro.client","code":408,"detail":"<nil>","status":"Request Timeout"}`)
|
||||
|
||||
err := waitForPlanDelegateExecution(done, taskSvc, new(NotifyService))
|
||||
err := waitForPlanDelegateExecution(done, taskSvc, new(NotifyService), nil)
|
||||
if err == nil {
|
||||
t.Fatal("waitForPlanDelegateExecution returned nil, want timeout before notify to fail")
|
||||
}
|
||||
@@ -493,6 +733,7 @@ func TestNotifyServiceCollapsesProviderReadinessParaphrases(t *testing.T) {
|
||||
requests := []SendRequest{
|
||||
{To: "owner@acme.com", Message: "The launch plan is ready"},
|
||||
{To: "owner @ acme.com", Message: "Launch plan ready."},
|
||||
{To: "owner at acme dot com", Message: "The launch plan is ready."},
|
||||
{To: "launch owner", Message: "The launch readiness plan is prepared."},
|
||||
{To: "plan owner", Message: "Launch plan is complete!"},
|
||||
}
|
||||
|
||||
@@ -206,10 +206,10 @@ func writeSummaryMarkdown(path string, summary conformanceSummary) error {
|
||||
|
||||
func capabilityMarkdown(rows []ai.CapabilityRow) string {
|
||||
var b strings.Builder
|
||||
b.WriteString("| Provider | Model | Image | Video | Streaming |\n")
|
||||
b.WriteString("| --- | --- | --- | --- | --- |\n")
|
||||
b.WriteString("| Provider | Model | Image | Video | Streaming | Tool streaming |\n")
|
||||
b.WriteString("| --- | --- | --- | --- | --- | --- |\n")
|
||||
for _, row := range rows {
|
||||
fmt.Fprintf(&b, "| %s | %s | %s | %s | %s |\n", row.Provider, mark(row.Model), mark(row.Image), mark(row.Video), mark(row.Stream))
|
||||
fmt.Fprintf(&b, "| %s | %s | %s | %s | %s | %s |\n", row.Provider, mark(row.Model), mark(row.Image), mark(row.Video), mark(row.Stream), mark(row.ToolStream))
|
||||
}
|
||||
return b.String()
|
||||
}
|
||||
@@ -250,9 +250,9 @@ func mark(ok bool) string {
|
||||
|
||||
func printCapabilityMatrix() {
|
||||
fmt.Println("Provider capability matrix:")
|
||||
fmt.Println("provider model image video stream")
|
||||
fmt.Println("provider model image video stream tool-stream")
|
||||
for _, row := range ai.CapabilityRows() {
|
||||
fmt.Printf("%-12s %-5s %-5s %-5s %-6s\n", row.Provider, yesNo(row.Model), yesNo(row.Image), yesNo(row.Video), yesNo(row.Stream))
|
||||
fmt.Printf("%-12s %-5s %-5s %-5s %-6s %-11s\n", row.Provider, yesNo(row.Model), yesNo(row.Image), yesNo(row.Video), yesNo(row.Stream), yesNo(row.ToolStream))
|
||||
}
|
||||
fmt.Println()
|
||||
}
|
||||
@@ -421,7 +421,7 @@ func runAgentConformance(provider string, timeout time.Duration) error {
|
||||
if provider == "mock" {
|
||||
testProvider = "fake"
|
||||
}
|
||||
cmd := exec.CommandContext(ctx, "go", "test", "./agent", "-run", "TestAgentProviderConformanceMatrix", "-count=1", "-v")
|
||||
cmd := exec.CommandContext(ctx, "go", "test", "./agent", "-run", "TestAgentProvider(ConformanceMatrix|StreamConformanceMatrix)", "-count=1", "-v")
|
||||
cmd.Dir = repoRoot()
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
|
||||
@@ -93,7 +93,7 @@ func TestWriteCapabilityMarkdown(t *testing.T) {
|
||||
}
|
||||
got := string(b)
|
||||
for _, want := range []string{
|
||||
"| Provider | Model | Image | Video | Streaming |",
|
||||
"| Provider | Model | Image | Video | Streaming | Tool streaming |",
|
||||
"| mock | ✅ | — | — | — |",
|
||||
"| vision | — | ✅ | ✅ | — |",
|
||||
} {
|
||||
|
||||
@@ -269,13 +269,21 @@ func completeNotifyOnObservedSideEffect(ctx context.Context, in flow.State, ntf
|
||||
in.Data = []byte("Buyer notified.")
|
||||
return in, nil
|
||||
}
|
||||
wait := time.NewTimer(25 * time.Millisecond)
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
if dispatchErr != nil {
|
||||
return in, dispatchErr
|
||||
if !wait.Stop() {
|
||||
<-wait.C
|
||||
}
|
||||
return in, ctx.Err()
|
||||
case <-time.After(25 * time.Millisecond):
|
||||
if dispatchErr == nil {
|
||||
return in, ctx.Err()
|
||||
}
|
||||
// A timed-out Agent.Chat call can report the caller context as done
|
||||
// while the remote agent is still finishing its notify tool call.
|
||||
// Keep watching for the idempotent side effect until the local settle
|
||||
// window expires so a post-side-effect timeout does not strand the
|
||||
// durable checkout run as pending.
|
||||
case <-wait.C:
|
||||
}
|
||||
}
|
||||
if dispatchErr != nil {
|
||||
@@ -349,14 +357,55 @@ func check(cond bool, format string, args ...any) {
|
||||
// should not depend on a live model deciding to send another notification.
|
||||
func a2aReachable(ctx context.Context, base, agent string) error {
|
||||
probe := "A2A reachability probe only. Reply with the words concierge reachable. Do not call tools or send notifications."
|
||||
reply, err := a2a.NewClient(base+"/agents/"+agent).Send(ctx, probe)
|
||||
if err != nil {
|
||||
return err
|
||||
deadline, ok := ctx.Deadline()
|
||||
if !ok {
|
||||
deadline = time.Now().Add(10 * time.Second)
|
||||
}
|
||||
if strings.TrimSpace(reply) == "" {
|
||||
return fmt.Errorf("empty A2A reply")
|
||||
|
||||
var lastErr error
|
||||
for attempt := 1; ; attempt++ {
|
||||
if err := ctx.Err(); err != nil {
|
||||
if lastErr != nil {
|
||||
return fmt.Errorf("A2A reachability probe failed after %d attempt(s): %w", attempt-1, lastErr)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
remaining := time.Until(deadline)
|
||||
if remaining <= 0 {
|
||||
if lastErr != nil {
|
||||
return fmt.Errorf("A2A reachability probe failed after %d attempt(s): %w", attempt-1, lastErr)
|
||||
}
|
||||
return context.DeadlineExceeded
|
||||
}
|
||||
|
||||
attemptTimeout := 4 * time.Second
|
||||
if remaining < attemptTimeout {
|
||||
attemptTimeout = remaining
|
||||
}
|
||||
attemptCtx, cancel := context.WithTimeout(ctx, attemptTimeout)
|
||||
reply, err := a2a.NewClient(base+"/agents/"+agent).Send(attemptCtx, probe)
|
||||
cancel()
|
||||
if err == nil && strings.TrimSpace(reply) != "" {
|
||||
return nil
|
||||
}
|
||||
if err == nil {
|
||||
err = fmt.Errorf("empty A2A reply")
|
||||
}
|
||||
lastErr = err
|
||||
|
||||
if time.Until(deadline) <= 0 {
|
||||
return fmt.Errorf("A2A reachability probe failed after %d attempt(s): %w", attempt, lastErr)
|
||||
}
|
||||
time.Sleep(minDuration(200*time.Millisecond*time.Duration(attempt), time.Until(deadline)))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func minDuration(a, b time.Duration) time.Duration {
|
||||
if a < b {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
func providerKey(provider string) string {
|
||||
|
||||
@@ -3,6 +3,9 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -25,6 +28,31 @@ func TestUniverseHarnessContract(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestA2AReachableRetriesTransientTimeout(t *testing.T) {
|
||||
var calls int64
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if got, want := r.URL.Path, "/agents/concierge"; got != want {
|
||||
t.Fatalf("path = %q, want %q", got, want)
|
||||
}
|
||||
if atomic.AddInt64(&calls, 1) == 1 {
|
||||
time.Sleep(5 * time.Second)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
fmt.Fprint(w, `{"jsonrpc":"2.0","id":1,"result":{"kind":"task","id":"task-1","contextId":"ctx-1","status":{"state":"completed"},"artifacts":[{"artifactId":"artifact-1","parts":[{"kind":"text","text":"concierge reachable"}]}]}}`)
|
||||
}))
|
||||
defer srv.Close()
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 6*time.Second)
|
||||
defer cancel()
|
||||
if err := a2aReachable(ctx, srv.URL, "concierge"); err != nil {
|
||||
t.Fatalf("a2aReachable returned error: %v", err)
|
||||
}
|
||||
if got := atomic.LoadInt64(&calls); got < 2 {
|
||||
t.Fatalf("A2A calls = %d, want retry after transient timeout", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNotifyStepCompletesAfterObservedSideEffectTimeout(t *testing.T) {
|
||||
ntf := new(Notify)
|
||||
before := atomic.LoadInt64(&ntf.sent)
|
||||
@@ -69,6 +97,42 @@ func TestNotifyStepCompletesAfterObservedSideEffectTimeout(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestNotifyStepWaitsForObservedSideEffectAfterCanceledDispatchContext(t *testing.T) {
|
||||
ntf := new(Notify)
|
||||
before := atomic.LoadInt64(&ntf.sent)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancel()
|
||||
|
||||
go func() {
|
||||
time.Sleep(30 * time.Millisecond)
|
||||
var rsp SendResponse
|
||||
if err := ntf.Send(context.Background(), &SendRequest{
|
||||
To: "buyer@acme.com",
|
||||
Message: "Your order is confirmed.",
|
||||
}, &rsp); err != nil {
|
||||
t.Errorf("send notification: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
out, err := completeNotifyOnObservedSideEffect(
|
||||
ctx,
|
||||
flow.State{Data: []byte(`{"order":"order-1"}`)},
|
||||
ntf,
|
||||
before,
|
||||
time.Second,
|
||||
errors.New("client observed timeout"),
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("notify completion returned error: %v", err)
|
||||
}
|
||||
if got := out.String(); got != "Buyer notified." {
|
||||
t.Fatalf("result = %q, want Buyer notified.", got)
|
||||
}
|
||||
if got := atomic.LoadInt64(&ntf.sent); got != 1 {
|
||||
t.Fatalf("notifications sent = %d, want 1", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNotifyStepRejectsClaimedCompletionWithoutSideEffect(t *testing.T) {
|
||||
ntf := new(Notify)
|
||||
before := atomic.LoadInt64(&ntf.sent)
|
||||
|
||||
@@ -8,9 +8,9 @@ scripted so CI can run it on every push without external services or model keys.
|
||||
|
||||
1. **Scaffold** — the maintained `micro new` 0→1 contract still creates
|
||||
runnable services from a clean workspace.
|
||||
2. **First agent** — `micro agent preflight`, `micro run`, `micro chat`, and
|
||||
`micro inspect agent <name>` remain available as the documented first-agent
|
||||
walkthrough path.
|
||||
2. **First agent** — `micro agent demo`, `micro examples`, `micro agent preflight`,
|
||||
`micro run`, `micro chat`, and `micro inspect agent <name>` remain available
|
||||
as the documented first-agent walkthrough path.
|
||||
3. **Run** — `micro run` remains available as the local development entry point.
|
||||
4. **Chat** — `micro chat` remains available as the interactive agent entry point.
|
||||
5. **Inspect/debugging** — `micro inspect agent <name>`, `micro agent history <name>`,
|
||||
@@ -32,8 +32,12 @@ and A2A with only the LLM mocked.
|
||||
|
||||
The default GitHub harness workflow runs this script on every push and pull
|
||||
request after the install smoke check and 0→1 scaffold contract. Developers can
|
||||
verify the first-agent on-ramp links alone with `make docs-wayfinding`, verify
|
||||
the installer seam alone with `make install-smoke`, run just the documented
|
||||
verify the first-agent on-ramp links and CLI command-output parity with
|
||||
`make docs-wayfinding` whenever README or website first-agent breadcrumbs,
|
||||
`micro agent demo`, `micro examples`, or `micro zero-to-hero` change. That
|
||||
check is provider-free and fails if documented command names, guide links, or
|
||||
maintained no-secret example paths drift from the CLI outputs. To verify the
|
||||
installed first-run CLI seam alone, use `make install-smoke`; to run just the documented
|
||||
agent debugging quickcheck with
|
||||
`go test ./internal/harness/zero-to-hero-ci -run TestNoSecretFirstAgentDebuggingSmoke -count=1`,
|
||||
or run the same no-secret contract locally with:
|
||||
|
||||
@@ -20,12 +20,13 @@ func TestZeroToHeroReferenceDocs(t *testing.T) {
|
||||
guide := readFile(t, filepath.Join(root, "internal", "website", "docs", "guides", "zero-to-hero.md"))
|
||||
for _, want := range []string{
|
||||
"make harness",
|
||||
"make inner-loop",
|
||||
"go test ./cmd/micro/cli/new -run TestZeroToOne -count=1",
|
||||
"go test ./cmd/micro -run TestFirstAgentWalkthroughCLIBoundaries -count=1",
|
||||
"go test ./cmd/micro -run TestZeroToHeroCLIBoundaries -count=1",
|
||||
"go test ./cmd/micro/cli/deploy -run TestDeployDryRun -count=1",
|
||||
"go test ./examples/first-agent -run TestRunFirstAgent -count=1",
|
||||
"go test ./examples/support -run 'TestRunSupportMockSmoke|TestZeroToHeroReadmeDocumentsLifecycle' -count=1",
|
||||
"go test ./examples/support -run 'TestRunSupportMockSmoke|TestZeroToHeroReadmeDocumentsLifecycle|TestZeroToHeroInspectTranscript' -count=1",
|
||||
"./internal/harness/zero-to-hero-ci/run.sh",
|
||||
"micro zero-to-hero",
|
||||
"go run ./internal/harness/agent-flow",
|
||||
@@ -41,20 +42,36 @@ func TestZeroToHeroReferenceDocs(t *testing.T) {
|
||||
runScript := readFile(t, filepath.Join(root, "internal", "harness", "zero-to-hero-ci", "run.sh"))
|
||||
for _, want := range []string{
|
||||
"go test ./cmd/micro/cli/new -run TestZeroToOne -count=1",
|
||||
"go test ./cmd/micro -run 'TestFirstAgentWalkthroughCLIBoundaries|TestZeroToHeroCLIBoundaries' -count=1",
|
||||
"go test ./cmd/micro -run 'TestFirstAgentWalkthroughCLIBoundaries|TestExamplesWayfindingIndexStaysLinked|TestExamplesCommandPointsAtWayfindingIndex|TestZeroToHeroCLIBoundaries|TestZeroToHeroCommandPrintsMaintainedNoSecretPath' -count=1",
|
||||
"go test ./cmd/micro/cli/deploy -run TestDeployDryRun -count=1",
|
||||
"go test ./examples/first-agent -run TestRunFirstAgent -count=1",
|
||||
"go test ./examples/support -run 'TestRunSupportMockSmoke|TestZeroToHeroReadmeDocumentsLifecycle' -count=1",
|
||||
"go test ./examples/support -run 'TestRunSupportMockSmoke|TestZeroToHeroReadmeDocumentsLifecycle|TestZeroToHeroInspectTranscript' -count=1",
|
||||
} {
|
||||
if !strings.Contains(runScript, want) {
|
||||
t.Fatalf("0→hero CI run script missing lifecycle command %q", want)
|
||||
}
|
||||
}
|
||||
for _, want := range []string{
|
||||
"scaffold:",
|
||||
"run/chat/inspect:",
|
||||
"deploy dry-run:",
|
||||
"chat/inspect:",
|
||||
"first-agent app:",
|
||||
"0→hero app:",
|
||||
"flow history:",
|
||||
} {
|
||||
if !strings.Contains(runScript, want) {
|
||||
t.Fatalf("0→hero CI run script missing debuggable boundary label %q", want)
|
||||
}
|
||||
}
|
||||
|
||||
readme := readFile(t, filepath.Join(root, "README.md"))
|
||||
if !strings.Contains(readme, "internal/website/docs/guides/zero-to-hero.md") {
|
||||
t.Fatal("README does not point to the canonical 0→hero guide")
|
||||
}
|
||||
if !strings.Contains(readme, "make inner-loop") {
|
||||
t.Fatal("README does not expose the focused CLI inner-loop contract")
|
||||
}
|
||||
|
||||
nav := readFile(t, filepath.Join(root, "internal", "website", "_data", "navigation.yml"))
|
||||
if !strings.Contains(nav, "0→hero Reference") || !strings.Contains(nav, "/docs/guides/zero-to-hero.html") {
|
||||
@@ -62,6 +79,62 @@ func TestZeroToHeroReferenceDocs(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestZeroToHeroDeployDryRunCommandSmoke(t *testing.T) {
|
||||
root := filepath.Clean(filepath.Join("..", "..", ".."))
|
||||
absRoot, err := filepath.Abs(root)
|
||||
if err != nil {
|
||||
t.Fatalf("resolve repository root: %v", err)
|
||||
}
|
||||
|
||||
bin := filepath.Join(t.TempDir(), "micro")
|
||||
build := exec.Command("go", "build", "-o", bin, "./cmd/micro")
|
||||
build.Dir = absRoot
|
||||
if out, err := build.CombinedOutput(); err != nil {
|
||||
t.Fatalf("build micro CLI for deploy dry-run smoke: %v\n%s", err, out)
|
||||
}
|
||||
|
||||
workspace := t.TempDir()
|
||||
writeFile(t, filepath.Join(workspace, "micro.mu"), `service api
|
||||
path ./api
|
||||
|
||||
deploy prod
|
||||
ssh deploy@prod.example.com
|
||||
path /srv/micro
|
||||
`)
|
||||
if err := os.Mkdir(filepath.Join(workspace, "api"), 0o755); err != nil {
|
||||
t.Fatalf("create service dir: %v", err)
|
||||
}
|
||||
|
||||
cmd := exec.Command(bin, "deploy", "--dry-run", "prod")
|
||||
cmd.Dir = workspace
|
||||
cmd.Env = append(os.Environ(), "MICRO_CONFIG_FILE="+filepath.Join(workspace, "micro.mu"))
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
t.Fatalf("documented deploy dry-run command failed: %v\n%s", err, out)
|
||||
}
|
||||
|
||||
got := string(out)
|
||||
for _, want := range []string{
|
||||
"micro deploy --dry-run",
|
||||
"Target",
|
||||
"deploy@prod.example.com",
|
||||
"Remote path",
|
||||
"/srv/micro",
|
||||
"Services",
|
||||
"api",
|
||||
"No SSH, rsync, systemd, or remote deployment was performed.",
|
||||
} {
|
||||
if !strings.Contains(got, want) {
|
||||
t.Fatalf("deploy dry-run output missing %q:\n%s", want, got)
|
||||
}
|
||||
}
|
||||
|
||||
guide := readFile(t, filepath.Join(absRoot, "internal", "website", "docs", "guides", "zero-to-hero.md"))
|
||||
if !strings.Contains(guide, "micro deploy --dry-run prod") {
|
||||
t.Fatal("0→hero guide must document the same deploy dry-run command covered by CI")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGuidesNavigationLeadsWithDoing(t *testing.T) {
|
||||
root := filepath.Clean(filepath.Join("..", "..", ".."))
|
||||
nav := readFile(t, filepath.Join(root, "internal", "website", "_data", "navigation.yml"))
|
||||
@@ -216,10 +289,13 @@ func TestFirstAgentWayfindingDocs(t *testing.T) {
|
||||
links: []string{
|
||||
"internal/website/docs/guides/install-troubleshooting.md",
|
||||
"micro agent demo",
|
||||
"micro examples",
|
||||
"micro zero-to-hero",
|
||||
"internal/website/docs/guides/no-secret-first-agent.md",
|
||||
"internal/website/docs/guides/your-first-agent.md",
|
||||
"micro chat",
|
||||
"internal/website/docs/guides/debugging-agents.md",
|
||||
"micro inspect agent <name>",
|
||||
"internal/website/docs/guides/zero-to-hero.md",
|
||||
},
|
||||
},
|
||||
@@ -241,6 +317,26 @@ func TestFirstAgentWayfindingDocs(t *testing.T) {
|
||||
"./support/",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "repository examples wayfinding index",
|
||||
file: filepath.Join(root, "examples", "INDEX.md"),
|
||||
heading: "## Recommended adoption path",
|
||||
links: []string{
|
||||
"./hello-world/",
|
||||
"./first-agent/",
|
||||
"./support/",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "micro README first-agent on-ramp",
|
||||
file: filepath.Join(root, "cmd", "micro", "README.md"),
|
||||
heading: "## First agent on-ramp",
|
||||
links: []string{
|
||||
"micro agent demo",
|
||||
"micro examples",
|
||||
"micro zero-to-hero",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "website examples index",
|
||||
file: filepath.Join(root, "internal", "website", "docs", "examples", "index.md"),
|
||||
@@ -260,13 +356,16 @@ func TestFirstAgentWayfindingDocs(t *testing.T) {
|
||||
links: []string{
|
||||
"guides/install-troubleshooting.html",
|
||||
"micro agent demo",
|
||||
"micro examples",
|
||||
"micro zero-to-hero",
|
||||
"https://github.com/micro/go-micro/blob/master/examples/INDEX.md",
|
||||
"https://github.com/micro/go-micro/tree/master/examples/support",
|
||||
"https://github.com/micro/go-micro/tree/master/examples/first-agent",
|
||||
"guides/no-secret-first-agent.html",
|
||||
"guides/your-first-agent.html",
|
||||
"micro chat",
|
||||
"guides/debugging-agents.html",
|
||||
"micro inspect agent <name>",
|
||||
"guides/zero-to-hero.html",
|
||||
},
|
||||
},
|
||||
@@ -277,13 +376,16 @@ func TestFirstAgentWayfindingDocs(t *testing.T) {
|
||||
links: []string{
|
||||
"guides/install-troubleshooting.html",
|
||||
"micro agent demo",
|
||||
"micro examples",
|
||||
"micro zero-to-hero",
|
||||
"https://github.com/micro/go-micro/blob/master/examples/INDEX.md",
|
||||
"https://github.com/micro/go-micro/tree/master/examples/support",
|
||||
"https://github.com/micro/go-micro/tree/master/examples/first-agent",
|
||||
"guides/no-secret-first-agent.html",
|
||||
"guides/your-first-agent.html",
|
||||
"micro chat",
|
||||
"guides/debugging-agents.html",
|
||||
"micro inspect agent <name>",
|
||||
"guides/zero-to-hero.html",
|
||||
},
|
||||
},
|
||||
@@ -297,7 +399,9 @@ func TestFirstAgentWayfindingDocs(t *testing.T) {
|
||||
"https://github.com/micro/go-micro/tree/master/examples/support",
|
||||
"guides/no-secret-first-agent.html",
|
||||
"guides/your-first-agent.html",
|
||||
"micro chat",
|
||||
"guides/debugging-agents.html",
|
||||
"micro inspect agent <name>",
|
||||
"guides/zero-to-hero.html",
|
||||
},
|
||||
},
|
||||
@@ -322,6 +426,108 @@ func TestFirstAgentWayfindingDocs(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestFirstAgentWayfindingCanonicalTrailStaysInSync(t *testing.T) {
|
||||
root := filepath.Clean(filepath.Join("..", "..", ".."))
|
||||
onRampTrail := []string{
|
||||
"micro agent demo",
|
||||
"micro examples",
|
||||
"micro zero-to-hero",
|
||||
"examples/INDEX.md",
|
||||
"examples/first-agent",
|
||||
"examples/support",
|
||||
"no-secret-first-agent",
|
||||
"your-first-agent",
|
||||
"micro chat",
|
||||
"debugging-agents",
|
||||
"micro inspect agent <name>",
|
||||
"zero-to-hero",
|
||||
}
|
||||
checks := []struct {
|
||||
name string
|
||||
file string
|
||||
heading string
|
||||
markers []string
|
||||
}{
|
||||
{
|
||||
name: "README first-agent on-ramp",
|
||||
file: filepath.Join(root, "README.md"),
|
||||
heading: "### First agent on-ramp",
|
||||
markers: onRampTrail,
|
||||
},
|
||||
{
|
||||
name: "website docs index first-agent path",
|
||||
file: filepath.Join(root, "internal", "website", "docs", "index.md"),
|
||||
heading: "## Learn More",
|
||||
markers: onRampTrail,
|
||||
},
|
||||
{
|
||||
name: "website getting-started first-agent on-ramp",
|
||||
file: filepath.Join(root, "internal", "website", "docs", "getting-started.md"),
|
||||
heading: "### First-agent on-ramp",
|
||||
markers: onRampTrail,
|
||||
},
|
||||
{
|
||||
name: "website quickstart next steps",
|
||||
file: filepath.Join(root, "internal", "website", "docs", "quickstart.md"),
|
||||
heading: "## Next Steps",
|
||||
markers: onRampTrail,
|
||||
},
|
||||
{
|
||||
name: "examples map recommended adoption path",
|
||||
file: filepath.Join(root, "examples", "INDEX.md"),
|
||||
heading: "",
|
||||
markers: []string{
|
||||
"micro examples",
|
||||
"micro zero-to-hero",
|
||||
"examples/INDEX.md",
|
||||
"examples/first-agent",
|
||||
"examples/support",
|
||||
"zero-to-hero",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "no-secret first-agent guide next steps",
|
||||
file: filepath.Join(root, "internal", "website", "docs", "guides", "no-secret-first-agent.md"),
|
||||
heading: "",
|
||||
markers: []string{
|
||||
"micro agent demo",
|
||||
"examples/first-agent",
|
||||
"examples/support",
|
||||
"your-first-agent",
|
||||
"micro chat",
|
||||
"debugging-agents",
|
||||
"micro inspect agent <name>",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "0→hero guide related examples",
|
||||
file: filepath.Join(root, "internal", "website", "docs", "guides", "zero-to-hero.md"),
|
||||
heading: "",
|
||||
markers: []string{
|
||||
"micro zero-to-hero",
|
||||
"examples/first-agent",
|
||||
"examples/support",
|
||||
"micro inspect agent <name>",
|
||||
"zero-to-hero",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, check := range checks {
|
||||
t.Run(check.name, func(t *testing.T) {
|
||||
section := readFile(t, check.file)
|
||||
if check.heading != "" {
|
||||
section = firstMarkdownSection(t, section, check.heading)
|
||||
}
|
||||
for _, marker := range check.markers {
|
||||
if !containsWayfindingMarker(section, marker) {
|
||||
t.Fatalf("%s missing canonical first-agent wayfinding marker %q; keep README, website, examples, no-secret, and 0→hero surfaces aligned", check.name, marker)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestFirstAgentWayfindingLinkTargetsResolve(t *testing.T) {
|
||||
root := filepath.Clean(filepath.Join("..", "..", ".."))
|
||||
checks := []struct {
|
||||
@@ -344,6 +550,11 @@ func TestFirstAgentWayfindingLinkTargetsResolve(t *testing.T) {
|
||||
file: filepath.Join(root, "examples", "README.md"),
|
||||
heading: "## Recommended first-agent path",
|
||||
},
|
||||
{
|
||||
name: "repository examples wayfinding index",
|
||||
file: filepath.Join(root, "examples", "INDEX.md"),
|
||||
heading: "## Recommended adoption path",
|
||||
},
|
||||
{
|
||||
name: "website examples index",
|
||||
file: filepath.Join(root, "internal", "website", "docs", "examples", "index.md"),
|
||||
@@ -380,6 +591,99 @@ func TestFirstAgentWayfindingLinkTargetsResolve(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestFirstAgentGuideChainDocumentsRequiredNextSteps(t *testing.T) {
|
||||
root := filepath.Clean(filepath.Join("..", "..", ".."))
|
||||
checks := []struct {
|
||||
name string
|
||||
file string
|
||||
markers []string
|
||||
}{
|
||||
{
|
||||
name: "no-secret transcript hands off to live build and debug",
|
||||
file: filepath.Join(root, "internal", "website", "docs", "guides", "no-secret-first-agent.md"),
|
||||
markers: []string{
|
||||
"micro agent demo",
|
||||
"go run ./examples/first-agent",
|
||||
"go run ./examples/support",
|
||||
"go test ./examples/first-agent -run TestRunFirstAgent -count=1",
|
||||
"go test ./examples/support -run TestRunSupportMockSmoke -count=1",
|
||||
"make harness",
|
||||
"micro agent preflight",
|
||||
"micro run",
|
||||
"micro chat assistant",
|
||||
"micro inspect agent assistant",
|
||||
"Debugging your agent",
|
||||
"debugging-agents.html",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "your-first-agent keeps no-secret, preflight, doctor, inspect, and debug nearby",
|
||||
file: filepath.Join(root, "internal", "website", "docs", "guides", "your-first-agent.md"),
|
||||
markers: []string{
|
||||
"no-secret-first-agent.html",
|
||||
"go run ./examples/support",
|
||||
"micro agent preflight",
|
||||
"micro agent doctor",
|
||||
"micro run",
|
||||
"micro chat assistant",
|
||||
"micro inspect agent assistant",
|
||||
"debugging-agents.html",
|
||||
"zero-to-hero.html",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "debugging guide starts at install/preflight and preserves inspect/history recovery",
|
||||
file: filepath.Join(root, "internal", "website", "docs", "guides", "debugging-agents.md"),
|
||||
markers: []string{
|
||||
"install-troubleshooting.html",
|
||||
"micro agent preflight",
|
||||
"micro agent doctor",
|
||||
"micro run",
|
||||
"micro chat",
|
||||
"micro inspect agent support",
|
||||
"micro agent history",
|
||||
"go test ./internal/harness/zero-to-hero-ci -run TestNoSecretFirstAgentDebuggingSmoke -count=1",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "zero-to-hero guide exposes the provider-free contract commands",
|
||||
file: filepath.Join(root, "internal", "website", "docs", "guides", "zero-to-hero.md"),
|
||||
markers: []string{
|
||||
"go test ./internal/harness/zero-to-hero-ci -run TestFirstAgentWayfinding -count=1",
|
||||
"micro zero-to-hero",
|
||||
"go run ./examples/first-agent",
|
||||
"go run ./examples/support",
|
||||
"make harness",
|
||||
"go test ./cmd/micro -run TestFirstAgentWalkthroughCLIBoundaries -count=1",
|
||||
"go test ./internal/harness/zero-to-hero-ci -run TestNoSecretFirstAgentDebuggingSmoke -count=1",
|
||||
"make provider-conformance-mock",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, check := range checks {
|
||||
t.Run(check.name, func(t *testing.T) {
|
||||
doc := readFile(t, check.file)
|
||||
for _, marker := range check.markers {
|
||||
if !strings.Contains(doc, marker) {
|
||||
t.Fatalf("%s missing required first-agent next-step marker %q", check.name, marker)
|
||||
}
|
||||
if firstAgentMarkerIsLink(marker) {
|
||||
assertWayfindingTargetExists(t, root, check.file, marker)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func firstAgentMarkerIsLink(marker string) bool {
|
||||
return strings.HasSuffix(marker, ".html") ||
|
||||
strings.HasSuffix(marker, ".md") ||
|
||||
strings.HasPrefix(marker, "./") ||
|
||||
strings.HasPrefix(marker, "../") ||
|
||||
strings.HasPrefix(marker, "https://github.com/micro/go-micro/")
|
||||
}
|
||||
|
||||
func TestFirstAgentLifecycleCommandOrderIsDocumented(t *testing.T) {
|
||||
root := filepath.Clean(filepath.Join("..", "..", ".."))
|
||||
checks := []struct {
|
||||
@@ -553,6 +857,7 @@ func TestGettingStartedDocsLeadWithNoSecretFirstRun(t *testing.T) {
|
||||
"micro zero-to-hero",
|
||||
"guides/no-secret-first-agent.html",
|
||||
"guides/debugging-agents.html",
|
||||
"micro inspect agent <name>",
|
||||
"guides/zero-to-hero.html",
|
||||
},
|
||||
},
|
||||
@@ -805,6 +1110,43 @@ func markdownLinks(section string) []string {
|
||||
return links
|
||||
}
|
||||
|
||||
func containsWayfindingMarker(section, marker string) bool {
|
||||
if strings.Contains(section, marker) {
|
||||
return true
|
||||
}
|
||||
switch marker {
|
||||
case "examples/INDEX.md":
|
||||
return strings.Contains(section, "examples/INDEX.md") ||
|
||||
strings.Contains(section, "Recommended adoption path") ||
|
||||
strings.Contains(section, "examples wayfinding index") ||
|
||||
strings.Contains(section, "Examples wayfinding index") ||
|
||||
strings.Contains(section, "./INDEX.md")
|
||||
case "examples/first-agent":
|
||||
return strings.Contains(section, "examples/first-agent") ||
|
||||
strings.Contains(section, "./first-agent")
|
||||
case "examples/support":
|
||||
return strings.Contains(section, "examples/support") ||
|
||||
strings.Contains(section, "./support")
|
||||
case "no-secret-first-agent":
|
||||
return strings.Contains(section, "no-secret-first-agent") ||
|
||||
strings.Contains(section, "No-secret First Agent")
|
||||
case "your-first-agent":
|
||||
return strings.Contains(section, "your-first-agent") ||
|
||||
strings.Contains(section, "Your First Agent")
|
||||
case "debugging-agents":
|
||||
return strings.Contains(section, "debugging-agents") ||
|
||||
strings.Contains(section, "Debugging your agent")
|
||||
case "zero-to-hero":
|
||||
return strings.Contains(section, "zero-to-hero") ||
|
||||
strings.Contains(section, "0→hero")
|
||||
default:
|
||||
if strings.HasPrefix(marker, "micro inspect agent ") {
|
||||
return strings.Contains(section, "micro inspect agent ")
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func assertWayfindingTargetExists(t *testing.T, root, sourceFile, link string) {
|
||||
t.Helper()
|
||||
if !strings.Contains(link, "/") && !strings.Contains(link, ".") {
|
||||
|
||||
@@ -4,17 +4,36 @@ set -euo pipefail
|
||||
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd)"
|
||||
cd "$ROOT"
|
||||
|
||||
run_step() {
|
||||
local name=$1
|
||||
shift
|
||||
|
||||
printf '\n==> %s\n' "$name"
|
||||
printf '+ %q' "$@"
|
||||
printf '\n'
|
||||
"$@"
|
||||
}
|
||||
|
||||
# Keep the developer inner-loop boundaries executable and discoverable in CI
|
||||
# without secrets or long-running daemons.
|
||||
go test ./cmd/micro/cli/new -run TestZeroToOne -count=1
|
||||
go test ./cmd/micro -run 'TestFirstAgentWalkthroughCLIBoundaries|TestZeroToHeroCLIBoundaries' -count=1
|
||||
go test ./cmd/micro/cli/deploy -run TestDeployDryRun -count=1
|
||||
go test ./internal/harness/zero-to-hero-ci -run 'TestNoSecretFirstAgentTranscript|TestNoSecretFirstAgentDebuggingSmoke|TestZeroToHeroReferenceDocs|TestYourFirstAgentTutorialSmoke' -count=1
|
||||
# without secrets or long-running daemons. Step names mirror the documented
|
||||
# install → scaffold → run/chat → inspect → deploy-dry-run seams so failures
|
||||
# identify the broken part of the getting-started contract.
|
||||
run_step "scaffold: 0→1 service contract" \
|
||||
go test ./cmd/micro/cli/new -run TestZeroToOne -count=1
|
||||
run_step "run/chat/inspect: first-agent CLI boundaries" \
|
||||
go test ./cmd/micro -run 'TestFirstAgentWalkthroughCLIBoundaries|TestExamplesWayfindingIndexStaysLinked|TestExamplesCommandPointsAtWayfindingIndex|TestZeroToHeroCLIBoundaries|TestZeroToHeroCommandPrintsMaintainedNoSecretPath' -count=1
|
||||
run_step "deploy dry-run: configured target plan" \
|
||||
go test ./cmd/micro/cli/deploy -run TestDeployDryRun -count=1
|
||||
run_step "chat/inspect: no-secret first-agent transcript and docs" \
|
||||
go test ./internal/harness/zero-to-hero-ci -run 'TestNoSecretFirstAgentTranscript|TestNoSecretFirstAgentDebuggingSmoke|TestZeroToHeroReferenceDocs|TestZeroToHeroDeployDryRunCommandSmoke|TestYourFirstAgentTutorialSmoke' -count=1
|
||||
|
||||
# Deterministic no-secret reference scenarios. These use the real Go Micro
|
||||
# runtime and mock only the LLM provider. The support example is the maintained
|
||||
# runnable 0→hero app; keep it in this CI path so its documented run/chat/inspect
|
||||
# journey cannot drift from the framework.
|
||||
go test ./examples/first-agent -run TestRunFirstAgent -count=1
|
||||
go test ./examples/support -run 'TestRunSupportMockSmoke|TestZeroToHeroReadmeDocumentsLifecycle' -count=1
|
||||
go test ./internal/harness/universe ./internal/harness/plan-delegate -run 'Test.*Harness|TestPlanDelegateEndToEnd|TestPlanDelegateFlowHandoff' -count=1
|
||||
run_step "first-agent app: runnable provider-free example" \
|
||||
go test ./examples/first-agent -run TestRunFirstAgent -count=1
|
||||
run_step "0→hero app: support lifecycle smoke" \
|
||||
go test ./examples/support -run 'TestRunSupportMockSmoke|TestZeroToHeroReadmeDocumentsLifecycle|TestZeroToHeroInspectTranscript' -count=1
|
||||
run_step "flow history: deterministic services → agents → workflows harnesses" \
|
||||
go test ./internal/harness/universe ./internal/harness/plan-delegate -run 'Test.*Harness|TestPlanDelegateEndToEnd|TestPlanDelegateFlowHandoff' -count=1
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
---
|
||||
layout: blog
|
||||
title: "What's New in Go Micro: v6.3.15"
|
||||
permalink: /blog/34
|
||||
description: "Go Micro v6.3.15 tightens the first-agent on-ramp, adds Anthropic streaming, and hardens plan/delegate plus text tool-call recovery."
|
||||
---
|
||||
|
||||
# What's New in Go Micro: v6.3.15
|
||||
|
||||
*July 5, 2026 • By the Go Micro Team*
|
||||
|
||||
Go Micro v6.3.15 is a small but useful harness release: less friction for the first agent, better streaming provider coverage, and more reliable execution when models and delegates do not behave perfectly.
|
||||
|
||||
## Anthropic now streams
|
||||
|
||||
The Anthropic provider now supports Messages SSE streaming and is registered as a streaming-capable provider. That means Go Micro agents can use Anthropic in the same streaming path as the other streaming-capable providers, with request/response parser coverage and provider capability docs kept in sync.
|
||||
|
||||
## The first-agent path is easier to start
|
||||
|
||||
The on-ramp now has a smallest runnable first-agent example: a mock-model, no-secret agent you can run before adding provider keys. The CLI and docs also point new users toward the maintained first-agent path after scaffold/run milestones, so the next step after a service is clearer: run the example, build the agent, debug it, then walk the 0→hero services → agents → workflows path.
|
||||
|
||||
## Plan/delegate is more deterministic
|
||||
|
||||
Plan/delegate runs got another reliability pass. Completed plan steps are preserved, ordering is guarded, notify-before-completion is required in the flow path, and checkpoint continuation is more stable. These are the kinds of harness fixes that matter when an agent does real work over multiple tool calls instead of just answering a prompt.
|
||||
|
||||
## Tool-call recovery keeps improving
|
||||
|
||||
Provider text tool-call fallback paths now recover more of the awkward cases: tagged calls, `Create`-suffixed calls, mixed text/tool-call output, and AtlasCloud follow-up calls. The goal is pragmatic: when a weaker or non-standard provider emits something close to a tool call, the harness should still make progress when it can do so safely.
|
||||
|
||||
## A2A payment groundwork
|
||||
|
||||
The A2A gateway now has the shared payment-mandate foundation needed for AP2-style agent payment flows. It is groundwork, not a full product story yet, but it keeps Go Micro's agent interop and paid-tool direction moving together.
|
||||
|
||||
## Read the changelog
|
||||
|
||||
The full release notes are in the [CHANGELOG](https://github.com/micro/go-micro/blob/master/CHANGELOG.md).
|
||||
|
||||
---
|
||||
|
||||
*Go Micro is an open source agent harness and service framework for Go. [Star us on GitHub](https://github.com/micro/go-micro).*
|
||||
|
||||
<div class="post-nav">
|
||||
<div><a href="/blog/33">← The Loop, Shipped: Introducing micro loop</a></div>
|
||||
<div><a href="/blog/">All Posts</a></div>
|
||||
</div>
|
||||
@@ -11,6 +11,13 @@ permalink: /blog/
|
||||
|
||||
<div class="posts">
|
||||
|
||||
<article style="margin-bottom: 2rem; padding-bottom: 1.5rem; border-bottom: 1px solid #e5e5e5;">
|
||||
<h2 style="margin: 0 0 0.5rem;"><a href="/blog/34">What's New in Go Micro: v6.3.15</a></h2>
|
||||
<p class="meta" style="color: #666; font-size: 0.85rem;">July 5, 2026</p>
|
||||
<p>Go Micro v6.3.15 tightens the first-agent on-ramp, adds Anthropic streaming, hardens plan/delegate execution, and improves provider text tool-call recovery.</p>
|
||||
<a href="/blog/34">Read more →</a>
|
||||
</article>
|
||||
|
||||
<article style="margin-bottom: 2rem; padding-bottom: 1.5rem; border-bottom: 1px solid #e5e5e5;">
|
||||
<h2 style="margin: 0 0 0.5rem;"><a href="/blog/33">The Loop, Shipped: Introducing micro loop</a></h2>
|
||||
<p class="meta" style="color: #666; font-size: 0.85rem;">July 2, 2026</p>
|
||||
|
||||
@@ -57,14 +57,15 @@ After this quick start, follow the agent path in order:
|
||||
|
||||
1. [Install troubleshooting](guides/install-troubleshooting.html) — verify the CLI install before agent work.
|
||||
2. `micro agent demo` — print the provider-free first-agent demo command and next docs steps from the installed CLI.
|
||||
3. `micro examples` — print the maintained provider-free runnable examples in copy/paste order.
|
||||
4. `micro zero-to-hero` — print the maintained one-command no-secret lifecycle harness and runnable examples.
|
||||
5. [Examples wayfinding index](https://github.com/micro/go-micro/blob/master/examples/INDEX.md) — choose the smallest no-secret first-agent, maintained [0→hero support reference](https://github.com/micro/go-micro/tree/master/examples/support), and next interop examples from one map.
|
||||
6. [Smallest first-agent example](https://github.com/micro/go-micro/tree/master/examples/first-agent) — run one service-backed agent with a mock model and no provider key.
|
||||
7. [No-secret first-agent transcript](guides/no-secret-first-agent.html) — run a useful support agent with a mock model before setting up a provider key.
|
||||
8. [Your First Agent](guides/your-first-agent.html) — build a service-backed agent and talk to it with `micro chat`.
|
||||
9. [Debugging your agent](guides/debugging-agents.html) — inspect service registration, tool calls, run history, memory, provider failures, and flow handoffs when the agent surprises you.
|
||||
10. [0→hero reference path](guides/zero-to-hero.html) — prove the full scaffold → run → chat → inspect → deploy dry-run lifecycle with commands exercised by `make harness`.
|
||||
3. `micro agent quickcheck` (or `micro agent debug`) — when scaffold → run → chat → inspect stalls, print the short recovery map before you dive into the full debugging guide.
|
||||
4. `micro examples` — print the maintained provider-free runnable examples in copy/paste order.
|
||||
5. `micro zero-to-hero` — print the maintained one-command no-secret lifecycle harness and runnable examples.
|
||||
6. [Examples wayfinding index](https://github.com/micro/go-micro/blob/master/examples/INDEX.md) — choose the smallest no-secret first-agent, maintained [0→hero support reference](https://github.com/micro/go-micro/tree/master/examples/support), and next interop examples from one map.
|
||||
7. [Smallest first-agent example](https://github.com/micro/go-micro/tree/master/examples/first-agent) — run one service-backed agent with a mock model and no provider key.
|
||||
8. [No-secret first-agent transcript](guides/no-secret-first-agent.html) — run a useful support agent with a mock model before setting up a provider key.
|
||||
9. [Your First Agent](guides/your-first-agent.html) — build a service-backed agent and talk to it with `micro chat`.
|
||||
10. [Debugging your agent](guides/debugging-agents.html) — use `micro agent preflight` before `micro run`, `micro agent doctor` after `micro run`, then `micro chat` and `micro inspect agent <name>` to recover service registration, tool calls, run history, memory, provider failures, and flow handoffs when the agent surprises you.
|
||||
11. [0→hero reference path](guides/zero-to-hero.html) — prove the full scaffold → run → chat → inspect → deploy dry-run lifecycle with commands exercised by `make harness`.
|
||||
|
||||
## Write a Service
|
||||
|
||||
|
||||
@@ -30,23 +30,23 @@ imports are linked in:
|
||||
|
||||
```go
|
||||
for _, row := range ai.CapabilityRows() {
|
||||
fmt.Printf("%s: chat=%t image=%t video=%t stream=%t\n", row.Provider, row.Model, row.Image, row.Video, row.Stream)
|
||||
fmt.Printf("%s: chat=%t image=%t video=%t stream=%t tool_stream=%t\n", row.Provider, row.Model, row.Image, row.Video, row.Stream, row.ToolStream)
|
||||
}
|
||||
```
|
||||
|
||||
The built-in providers currently register these capability interfaces:
|
||||
|
||||
| Provider | Chat/text (`ai.Model`) | Image (`ai.ImageModel`) | Video (`ai.VideoModel`) | Streaming (`ai.Stream`) |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| `anthropic` | Yes | No | No | Yes |
|
||||
| `atlascloud` | Yes | Yes | Yes | Yes |
|
||||
| `gemini` | Yes | No | No | No |
|
||||
| `groq` | Yes | No | No | Yes |
|
||||
| `minimax` | Yes | No | No | Yes |
|
||||
| `mistral` | Yes | No | No | Yes |
|
||||
| `ollama` | Yes | No | No | Yes |
|
||||
| `openai` | Yes | Yes | No | Yes |
|
||||
| `together` | Yes | No | No | Yes |
|
||||
| Provider | Chat/text (`ai.Model`) | Image (`ai.ImageModel`) | Video (`ai.VideoModel`) | Streaming (`ai.Stream`) | Tool streaming |
|
||||
| --- | --- | --- | --- | --- | --- |
|
||||
| `anthropic` | Yes | No | No | Yes | Yes |
|
||||
| `atlascloud` | Yes | Yes | Yes | Yes | No |
|
||||
| `gemini` | Yes | No | No | No | No |
|
||||
| `groq` | Yes | No | No | Yes | Yes |
|
||||
| `minimax` | Yes | No | No | Yes | Yes |
|
||||
| `mistral` | Yes | No | No | Yes | Yes |
|
||||
| `ollama` | Yes | No | No | Yes | Yes |
|
||||
| `openai` | Yes | Yes | No | Yes | Yes |
|
||||
| `together` | Yes | No | No | Yes | Yes |
|
||||
|
||||
## Step 1: Implement the `ai.Model` Interface
|
||||
|
||||
|
||||
@@ -24,10 +24,11 @@ Use the recovery command that matches where you are in the first-agent journey:
|
||||
| Checkpoint | When to use it | Command |
|
||||
| --- | --- | --- |
|
||||
| Install troubleshooting | `micro` is not installed, not on `PATH`, or the shell cannot run it. | [Install troubleshooting](install-troubleshooting.html) |
|
||||
| Quick recovery map | The first-agent loop stalled and you want the short scaffold → run → chat → inspect checklist before reading this full guide. | `micro agent quickcheck` (alias: `micro agent debug`) |
|
||||
| Preflight before `micro run` | You have not started the local runtime yet and want to verify Go, CLI, provider-key, and gateway-port prerequisites. | `micro agent preflight` |
|
||||
| Doctor after `micro run` | `micro run` is active, but chat, the `/agent` gateway, agent registration, provider settings, or inspect/run history is not behaving. | `micro agent doctor` |
|
||||
|
||||
`micro agent preflight` is read-only and runs before the first local run; failed
|
||||
`micro agent quickcheck` is the quickest breadcrumb when you are unsure where the first-agent path failed: it prints the preflight, run, doctor, inspect, and no-secret fallback commands in one place. `micro agent preflight` is read-only and runs before the first local run; failed
|
||||
checks include `Fix:` and `Next:` lines for Go, CLI installation, provider-key
|
||||
setup, and the local gateway port. Once `micro run` is already up, switch to
|
||||
`micro agent doctor` so the recovery output follows the live gateway, chat
|
||||
|
||||
@@ -50,6 +50,29 @@ branches, create pull requests, and enable auto-merge. Run `gh auth setup-git` i
|
||||
the environment that will push branches so `git push` uses the same credentials
|
||||
as `gh`.
|
||||
|
||||
## Choosing an agent
|
||||
|
||||
The loop is **agent-agnostic by design**. Each run opens a fresh tracking issue
|
||||
and summons the agent with an `@mention` comment; the prompt file
|
||||
(`.github/loop/prompts/<role>.md`) is the instruction. Any coding agent that
|
||||
(a) responds to an `@mention` on an issue and (b) can open a PR with `gh` works —
|
||||
you select it with `--agent`.
|
||||
|
||||
- **Codex** (`--agent @codex`, the default). Point `--token-secret` at a PAT for
|
||||
the user account Codex follows, and make sure the Codex environment installs
|
||||
`gh` and runs `gh auth setup-git`. This is the path Go Micro itself runs on.
|
||||
- **Claude Code** (`--agent @claude`). Install
|
||||
[`anthropics/claude-code-action`](https://github.com/anthropics/claude-code-action)
|
||||
in the repo so a workflow responds to `@claude` comments and runs Claude with a
|
||||
repo-scoped token; then the loop's dispatch triggers it like any other mention.
|
||||
- **Any other mention-driven agent** — pass its handle to `--agent`. The
|
||||
mechanics don't care which agent it is.
|
||||
|
||||
Not supported by the mention model: agents triggered by **issue assignment**
|
||||
rather than a comment (e.g. GitHub Copilot's coding agent, which you assign an
|
||||
issue to). The dispatch would need an "assign" adapter for those; it isn't wired
|
||||
yet, so stick to mention-driven agents.
|
||||
|
||||
## 3. Make CI the gate
|
||||
|
||||
The loop should not be its own reviewer. Protect the default branch so PRs merge
|
||||
|
||||
@@ -34,7 +34,7 @@ func TestAIProviderGuideCapabilityMatrixMatchesRegistry(t *testing.T) {
|
||||
guide := string(b)
|
||||
|
||||
for _, row := range ai.CapabilityRows() {
|
||||
want := fmt.Sprintf("| `%s` | %s | %s | %s | %s |", row.Provider, yesNo(row.Model), yesNo(row.Image), yesNo(row.Video), yesNo(row.Stream))
|
||||
want := fmt.Sprintf("| `%s` | %s | %s | %s | %s | %s |", row.Provider, yesNo(row.Model), yesNo(row.Image), yesNo(row.Video), yesNo(row.Stream), yesNo(row.ToolStream))
|
||||
if !strings.Contains(guide, want) {
|
||||
t.Fatalf("AI provider guide capability matrix is stale; missing row %q", want)
|
||||
}
|
||||
|
||||
@@ -18,14 +18,14 @@ cloud credentials?"
|
||||
| Boundary | Contract | CI check |
|
||||
| --- | --- | --- |
|
||||
| Scaffold | `micro new` generates a runnable service with and without MCP support. | `go test ./cmd/micro/cli/new -run TestZeroToOne -count=1` |
|
||||
| First-agent wayfinding | README and the website getting-started docs keep the no-secret → first-agent → debugging → 0→hero links present and in order. | `go test ./internal/harness/zero-to-hero-ci -run TestFirstAgentWayfindingDocs -count=1` |
|
||||
| First-agent wayfinding | README, website index/quickstart, examples, and no-secret/0→hero docs keep the no-secret → first-agent → debugging → 0→hero links present and in order. | `go test ./internal/harness/zero-to-hero-ci -run TestFirstAgentWayfinding -count=1` |
|
||||
| First agent | `micro new`, `micro agent preflight`, `micro run`, `micro chat`, and `micro inspect agent <name>` stay available for the documented first-agent walkthrough. | `go test ./cmd/micro -run TestFirstAgentWalkthroughCLIBoundaries -count=1` |
|
||||
| Run | `micro run` remains the local development entry point. | `go test ./cmd/micro -run TestZeroToHeroCLIBoundaries -count=1` |
|
||||
| Chat | `micro chat` remains the interactive agent entry point. | `go test ./cmd/micro -run TestZeroToHeroCLIBoundaries -count=1` |
|
||||
| Inspect | `micro inspect agent <name>`, `micro agent history <name>`, `micro inspect flow <flow>`, and `micro flow runs <flow>` remain discoverable for run history; the no-secret debugging smoke seeds durable agent history and runs the documented inspect/history commands without provider keys. | `go test ./internal/harness/zero-to-hero-ci -run TestNoSecretFirstAgentDebuggingSmoke -count=1` |
|
||||
| Deploy | `micro deploy --dry-run` resolves deploy targets without touching remote infrastructure. | `go test ./cmd/micro/cli/deploy -run TestDeployDryRun -count=1` |
|
||||
| Deploy | `micro deploy --dry-run prod` resolves the documented deploy target without touching remote infrastructure. | `go test ./internal/harness/zero-to-hero-ci -run TestZeroToHeroDeployDryRunCommandSmoke -count=1` |
|
||||
| Smallest first agent | `examples/first-agent` runs one service-backed agent with a deterministic mock model and no provider key. | `go test ./examples/first-agent -run TestRunFirstAgent -count=1` |
|
||||
| Runtime reference app | `examples/support` runs typed services, an agent using those services as tools, an event-driven flow handoff, and an approval gate with only the model mocked. | `go test ./examples/support -run 'TestRunSupportMockSmoke|TestZeroToHeroReadmeDocumentsLifecycle' -count=1` |
|
||||
| Runtime reference app | `examples/support` runs typed services, an agent using those services as tools, an event-driven flow handoff, and an approval gate with only the model mocked. | `go test ./examples/support -run 'TestRunSupportMockSmoke|TestZeroToHeroReadmeDocumentsLifecycle|TestZeroToHeroInspectTranscript' -count=1` |
|
||||
| Runtime harnesses | Real services, agents, durable flows, store-backed history, delegation, and A2A run with only the model mocked. | `./internal/harness/zero-to-hero-ci/run.sh` and `make provider-conformance-mock` |
|
||||
|
||||
## Find the one-command entrypoint
|
||||
@@ -69,6 +69,12 @@ SSH access, or remote service is required.
|
||||
|
||||
## Run focused checks while iterating
|
||||
|
||||
Use the dedicated inner-loop target when you need the provider-free CLI contract in one focused command:
|
||||
|
||||
```sh
|
||||
make inner-loop
|
||||
```
|
||||
|
||||
Use the smaller checks when you are working on one seam:
|
||||
|
||||
```sh
|
||||
@@ -84,12 +90,13 @@ go test ./cmd/micro -run TestFirstAgentWalkthroughCLIBoundaries -count=1
|
||||
# CLI inner-loop commands: run, chat, inspect, flow runs, deploy --dry-run.
|
||||
go test ./cmd/micro -run TestZeroToHeroCLIBoundaries -count=1
|
||||
go test ./cmd/micro/cli/deploy -run TestDeployDryRun -count=1
|
||||
go test ./internal/harness/zero-to-hero-ci -run TestZeroToHeroDeployDryRunCommandSmoke -count=1
|
||||
|
||||
# Smallest no-secret service-backed first agent.
|
||||
go test ./examples/first-agent -run TestRunFirstAgent -count=1
|
||||
|
||||
# Maintained 0→hero support-desk reference app.
|
||||
go test ./examples/support -run 'TestRunSupportMockSmoke|TestZeroToHeroReadmeDocumentsLifecycle' -count=1
|
||||
go test ./examples/support -run 'TestRunSupportMockSmoke|TestZeroToHeroReadmeDocumentsLifecycle|TestZeroToHeroInspectTranscript' -count=1
|
||||
|
||||
# Durable services → agents → workflows reference scenarios.
|
||||
./internal/harness/zero-to-hero-ci/run.sh
|
||||
|
||||
@@ -16,20 +16,21 @@ It's built on a pluggable architecture of Go interfaces: service discovery, clie
|
||||
|
||||
## Learn More
|
||||
|
||||
Start with [Getting Started](getting-started.html) for install and the first local service. Then follow the first-agent on-ramp: `micro agent demo` for the installed no-secret CLI affordance, [examples wayfinding index](https://github.com/micro/go-micro/blob/master/examples/INDEX.md) for the maintained examples map, [the 0→hero support reference](https://github.com/micro/go-micro/tree/master/examples/support) for the full no-secret lifecycle example, [No-secret first-agent transcript](guides/no-secret-first-agent.html) to run a mock-model support agent, [Your First Agent](guides/your-first-agent.html) to build and chat with a service-backed agent, [Debugging your agent](guides/debugging-agents.html) to inspect runs and memory, and the [0→hero reference path](guides/zero-to-hero.html) to walk the full scaffold → run → chat → inspect → deploy dry-run lifecycle covered by CI.
|
||||
Start with [Getting Started](getting-started.html) for install and the first local service. Then follow the first-agent on-ramp in the same order as the README: `micro agent demo` for the installed no-secret CLI affordance, `micro examples` for the provider-free examples map, `micro zero-to-hero` for the maintained lifecycle harness, [examples wayfinding index](https://github.com/micro/go-micro/blob/master/examples/INDEX.md) for the runnable examples map, [the smallest first-agent example](https://github.com/micro/go-micro/tree/master/examples/first-agent) for the fastest provider-free run, [the 0→hero support reference](https://github.com/micro/go-micro/tree/master/examples/support) for the full no-secret lifecycle example, [No-secret first-agent transcript](guides/no-secret-first-agent.html) to run a mock-model support agent, [Your First Agent](guides/your-first-agent.html) to build a service-backed agent and talk to it with `micro chat`, [Debugging your agent](guides/debugging-agents.html) to use `micro inspect agent <name>` for runs and memory, and the [0→hero reference path](guides/zero-to-hero.html) to walk the full scaffold → run → chat → inspect → deploy dry-run lifecycle covered by CI.
|
||||
|
||||
Otherwise continue to read the docs for more information about the framework.
|
||||
|
||||
## Contents
|
||||
|
||||
- [Getting Started](getting-started.html)
|
||||
- [0→hero Reference](guides/zero-to-hero.html) - Walk scaffold → run → chat → inspect → deploy dry-run with CI-backed commands
|
||||
- [0→hero Reference](guides/zero-to-hero.html) - Walk scaffold → run → chat → `micro inspect agent <name>` → deploy dry-run with CI-backed commands
|
||||
- `micro agent demo` - Show the provider-free first-agent demo command and next docs steps
|
||||
- `micro examples` - Show provider-free first-agent examples in copy/paste order
|
||||
- [Examples wayfinding index](https://github.com/micro/go-micro/blob/master/examples/INDEX.md) - Choose the first-agent, support, and interop examples from one map
|
||||
- [Smallest first-agent example](https://github.com/micro/go-micro/tree/master/examples/first-agent) - Run one service-backed agent with a deterministic mock model
|
||||
- [0→hero support reference](https://github.com/micro/go-micro/tree/master/examples/support) - Run the maintained no-secret services → agents → workflows example
|
||||
- [No-secret first-agent transcript](guides/no-secret-first-agent.html) - Run the first useful agent path without a provider key
|
||||
- [Your First Agent](guides/your-first-agent.html) - Build a service-backed agent end to end
|
||||
- [Your First Agent](guides/your-first-agent.html) - Build a service-backed agent and talk to it with `micro chat`
|
||||
- [MCP & AI Agents](mcp.html) - Turn services into AI-callable tools with the Model Context Protocol
|
||||
- [CLI & Gateway Guide](guides/cli-gateway.html) - Development vs Production modes
|
||||
- [`micro loop` quickstart](guides/micro-loop.html) - Scaffold an autonomous CI-gated improvement loop
|
||||
@@ -52,9 +53,9 @@ Otherwise continue to read the docs for more information about the framework.
|
||||
|
||||
## AI & Agents
|
||||
|
||||
- [0→hero Reference](guides/zero-to-hero.html) - Walk scaffold → run → chat → inspect → deploy dry-run with CI-backed commands
|
||||
- [0→hero Reference](guides/zero-to-hero.html) - Walk scaffold → run → chat → `micro inspect agent <name>` → deploy dry-run with CI-backed commands
|
||||
- [No-secret first-agent transcript](guides/no-secret-first-agent.html) - Run the first useful agent path without a provider key
|
||||
- [Your First Agent](guides/your-first-agent.html) - Build a service-backed agent end to end
|
||||
- [Your First Agent](guides/your-first-agent.html) - Build a service-backed agent and talk to it with `micro chat`
|
||||
- [Building AI-Native Services](guides/ai-native-services.html) - End-to-end tutorial for MCP-enabled services
|
||||
- [MCP Security Guide](guides/mcp-security.html) - Auth, scopes, rate limiting, and audit logging
|
||||
- [Tool Description Best Practices](guides/tool-descriptions.html) - Writing docs that make agents effective
|
||||
|
||||
@@ -49,7 +49,7 @@ You now have the service half of the services → agents → workflows lifecycle
|
||||
6. **[Smallest first-agent example](https://github.com/micro/go-micro/tree/master/examples/first-agent)** - run a mock-model, no-secret agent before adding provider keys.
|
||||
7. **[No-secret first-agent transcript](guides/no-secret-first-agent.html)** - run a useful support agent with a mock model before setting up a provider key.
|
||||
8. **[Your First Agent](guides/your-first-agent.html)** - turn this service into an agent-callable tool, chat with it, and learn the `micro agent preflight` → `micro run` → `micro chat` loop.
|
||||
9. **[Debugging your agent](guides/debugging-agents.html)** - inspect service registration, tool calls, run history, memory, provider failures, and flow handoffs when the agent does something surprising.
|
||||
9. **[Debugging your agent](guides/debugging-agents.html)** - use `micro inspect agent <name>` to inspect service registration, tool calls, run history, memory, provider failures, and flow handoffs when the agent does something surprising.
|
||||
10. **[0→hero Reference](guides/zero-to-hero.html)** - walk the maintained scaffold → run → chat → inspect → deploy dry-run path that proves services, agents, and workflows together.
|
||||
|
||||
After that first-agent path, branch out to:
|
||||
|
||||
@@ -11,7 +11,7 @@ Go Micro is a framework for building **agents and services** in Go. An agent is
|
||||
The foundation is in place:
|
||||
|
||||
- **Services** — register, discover, RPC, events; every endpoint is automatically an MCP tool.
|
||||
- **Agents** — a model with memory and tools that manages services, with `plan`, `delegate`, and guardrails (`MaxSteps`, `LoopLimit`, `ApproveTool`) built in, plus tool-execution middleware (`WrapTool`) and run metadata.
|
||||
- **Agents** — a model with memory and tools that manages services, with `plan`, `delegate`, guardrails (`MaxSteps`, `LoopLimit`, `ApproveTool`), tool-execution middleware (`WrapTool`), run metadata, checkpoint/resume, and OpenTelemetry run spans built in.
|
||||
- **Flows** — durable, event-driven workflows: ordered steps that checkpoint and resume after a crash.
|
||||
- **Interop** — the MCP gateway (services as tools) and the A2A gateway (agents as agents, both directions, including A2A streaming, push notifications, and multi-turn continuation), both generated from the registry; x402 for paid tools.
|
||||
- **Secure by default** — TLS verification on, state scoped per component.
|
||||
@@ -34,10 +34,24 @@ The priority is that what exists works everywhere, under real conditions.
|
||||
- **Failure & resilience.** Provider timeouts, rate limits, and cancellation mid-run; deadline/`context` propagation through the agent loop; retry and backoff at the model call.
|
||||
- **The getting-started contract.** Define and CI-verify the 0→1 and 0→hero flows so they can't silently break.
|
||||
|
||||
## Shipped agent depth
|
||||
|
||||
- **Durable agent loop.** Opt-in `Checkpoint` support now lets agent `Ask` and
|
||||
streaming runs persist, list pending work, and resume without replaying completed
|
||||
tool calls. Human-input pauses resume through explicit input helpers.
|
||||
- **Agent observability.** `RunInfo` now feeds OpenTelemetry spans and events for
|
||||
agent runs, model turns, tool calls, retries, delegation lineage, and resume
|
||||
checkpoints so production runs are traceable.
|
||||
|
||||
## Next — agentic depth
|
||||
|
||||
- **Streaming.** Broaden provider-backed `ai.Stream` coverage and keep chat plus A2A `message/stream` working end to end for real chat and long-task UX.
|
||||
- **Agent observability.** Wire the new `RunInfo` into OpenTelemetry spans so a run — steps, tool calls, delegation — is traceable. This is also what anyone running it in production will need.
|
||||
- **Resume operations polish.** Keep improving CLI/docs breadcrumbs for finding
|
||||
pending agent runs and deciding whether to call resume, resume-input, or stream
|
||||
resume in production.
|
||||
- **Observability hardening.** Keep span attributes and run inspection coherent
|
||||
across agents, flows, and gateways as more providers and workflow paths are
|
||||
exercised.
|
||||
|
||||
## Later
|
||||
|
||||
|
||||
@@ -215,7 +215,10 @@ func AgentWithCheckpoint(c Checkpoint) AgentOption { return agent.WithCheckpoint
|
||||
func AgentPending(ctx context.Context, a Agent) ([]FlowRun, error) { return agent.Pending(ctx, a) }
|
||||
|
||||
// AgentResume resumes a checkpointed agent run by id. Completed runs return
|
||||
// the persisted response without calling the model or replaying tool calls.
|
||||
// the persisted response, including completed tool-call metadata, without
|
||||
// calling the model or replaying tool calls. Incomplete runs resume from the
|
||||
// saved prompt plus completed tool checkpoints; a provider call interrupted
|
||||
// mid-stream is retried rather than continued byte-for-byte.
|
||||
func AgentResume(ctx context.Context, a Agent, runID string) (*AgentResponse, error) {
|
||||
return agent.Resume(ctx, a, runID)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user