From 157d7407e26ff80c90becdd27f98f0925746a2f6 Mon Sep 17 00:00:00 2001 From: Hugo Richard Date: Mon, 16 Nov 2026 17:02:06 +0000 Subject: [PATCH] docs: address self-improving agent guide feedback - Note that granting team access is a separate step from signing in to the Vercel MCP. - Match MAINTAINERS on Slack member IDs, since eve's principal uses the installation workspace. - Test the schedules in production with `vercel schedules invoke`. - Explain why private sessions record no tool inputs or outputs, and how to change it. - Add troubleshooting for token failures, 403 responses, and the shared-grant workaround. - Note in the examples/eve README that `eve add channel/slack` picks its own connector name. --- .../docs/5.guides/8.self-improving-agent.md | 89 +++++++++++++++---- examples/eve/README.md | 2 + 2 files changed, 76 insertions(+), 15 deletions(-) diff --git a/apps/docs/content/docs/5.guides/8.self-improving-agent.md b/apps/docs/content/docs/5.guides/8.self-improving-agent.md index 1357663..3522f57 100644 --- a/apps/docs/content/docs/5.guides/8.self-improving-agent.md +++ b/apps/docs/content/docs/5.guides/8.self-improving-agent.md @@ -53,7 +53,7 @@ Every Monday, a thread in a Slack channel links the pull requests the review ope - **The `examples/eve` agent, deployed.** Follow its [README](https://github.com/vercel-labs/github-tools/tree/main/examples/eve#set-up) through the Slack channel and the deploy. - **The agent's code in its own GitHub repository**, with the agent's GitHub App installed on it. The App needs Contents (write) and Pull requests (write) there, the [`pr-author` permissions](/auth#permissions-per-preset). With the Deploy button, Vercel creates that repository and connects it to the project, so merging a pull request also deploys it. -- **Agent Runs that record your runs.** Agent Runs is in [beta](https://vercel.com/docs/release-phases#beta) on all plans, billed at [Tracing rates](https://vercel.com/docs/tracing/configure-tracing#usage-and-pricing), and keeps runs for 30 days. It only records a run when the project samples traces. `npx eve deploy` sets that up for a project it creates. For any other project, such as one created with the Deploy button, add a 100% rule under **Settings → Tracing**, as [Agent Runs](https://vercel.com/docs/agent-runs#configure-tracing-for-existing-projects) describes. Then use the agent for a few days, so the review has runs to read. The project's **Observability → Agent Runs** page lists them. +- **Agent Runs that record your runs.** Agent Runs is in [beta](https://vercel.com/docs/release-phases#beta) on all plans, billed at [Tracing rates](https://vercel.com/docs/tracing/configure-tracing#usage-and-pricing), and keeps runs for 30 days. It only records a run when the project samples traces. `npx eve deploy` sets that up for a project it creates. For any other project, such as one created with the Deploy button, add a 100% rule under **Settings → Tracing**, as [Agent Runs](https://vercel.com/docs/agent-runs#configure-tracing-for-existing-projects) describes. Then use the agent for a few days, so the review has runs to read. The project's **Observability → Agent Runs** page lists them. By default, a run in a direct message or a private channel records tool names but not their inputs and outputs. [Let the review read tool inputs and outputs](#let-the-review-read-tool-inputs-and-outputs) covers what that leaves out and how to change it. - **A private Slack channel for the reports**, with the Slack app invited. A trace holds what people asked the agent, so keep the reports where only maintainers read them. ## 1. Create a Vercel connector @@ -64,7 +64,7 @@ The weekly review runs on a schedule, with nobody signed in, so the agent can't vercel connect create vercel --connection-method mcp --name github-agent ``` -`--connection-method mcp` picks the Vercel MCP. Without it, the CLI asks whether to connect the Vercel REST API or the MCP. If the CLI opens your browser, sign in with a Vercel account that has access to the agent's project. +`--connection-method mcp` picks the Vercel MCP. Without it, the CLI asks whether to connect the Vercel REST API or the MCP. If the CLI opens your browser, sign in with a Vercel account that has access to the agent's project, and grant access to the team that owns it. Signing in and granting team access are [two separate steps](https://vercel.com/docs/agent-resources/vercel-mcp/tools#sign-in-and-grant-team-access): without the team grant, the token works but every call to the agent's project returns `403`. Then let the agent's project use the connector: @@ -84,9 +84,11 @@ The connection, the extension and the schedules read five values from the enviro | `AGENT_PROJECT_ID` | `projectId` in `.vercel/project.json` | | `AGENT_REPOSITORY` | The agent's own repository, such as `my-org/github-agent` | | `REVIEW_SLACK_CHANNEL` | The ID of the reports channel, such as `C0123ABC`. It's at the bottom of the channel's details in Slack. | -| `MAINTAINERS` | The people who may ask the agent about its runs, comma-separated, as `slack::`. For example, `slack:T0123ABC:U0456DEF`. | +| `MAINTAINERS` | The Slack member IDs of the people who may ask the agent about its runs, comma-separated, such as `U0456DEF,U0789GHI`. | -`.vercel/project.json` is written when you link the project. eve names a Slack user `slack::`: `` is the workspace ID, the `T…` part of the address when you open Slack in a browser (`app.slack.com/client/T0123ABC/…`), and `` is the member ID, which **Copy member ID** in a Slack profile copies. +`.vercel/project.json` is written when you link the project. To find a member ID, open the person's Slack profile and select **Copy member ID**. + +eve identifies a Slack user as `slack::`, where `` is the workspace the Slack app is installed in. On Enterprise Grid, that isn't always the workspace in the Slack URL, so the connection below matches the member ID alone. Add each variable to the project: @@ -106,6 +108,8 @@ import { defineMcpClientConnection } from 'eve/connections' import { isScheduleAuth } from 'eve/schedules' const maintainers = new Set((process.env.MAINTAINERS ?? '').split(',')) +const isMaintainer = (principalId: string) => + principalId.startsWith('slack:') && maintainers.has(principalId.split(':').at(-1)!) export default defineMcpClientConnection({ url: 'https://mcp.vercel.com', @@ -121,7 +125,7 @@ export default defineMcpClientConnection({ }, auth: ({ session }) => { const caller = session.auth.current - if (isScheduleAuth(caller) || (caller !== null && maintainers.has(caller.principalId))) { + if (isScheduleAuth(caller) || (caller !== null && isMaintainer(caller.principalId))) { return connect({ connector: 'vercel/github-agent', principalType: 'app' }) } return { @@ -138,7 +142,7 @@ Three options keep this connection safe: - **`providedArguments`** fills in `teamId` and `projectId` on every call. The model never sees these two inputs, so it can only read this agent's project. - **`auth`** hands out a token only to a scheduled run or to someone in `MAINTAINERS`. Anyone else who asks the agent about its runs in Slack gets an error, not your runtime logs. -`principalType: 'app'` means the token belongs to the agent, not to a person, which is what a scheduled run needs. +`principalType: 'app'` means the token belongs to the agent, not to a person, which is what a scheduled run needs. If every call fails with `OAuth token request failed`, see [Troubleshooting](#troubleshooting). ## 4. Let the review open its pull requests @@ -189,7 +193,7 @@ description: Review your own production runs for failed, slow and expensive work 1. List the last 7 days of runs with `vercel__list_agent_runs` (`period: '7d'`, `pageSize: 100`). List the 7 days before them with `from` and `to`, to compare. 2. Pick three groups of up to three runs: runs that failed or never answered, the slowest runs, and the runs that used the most tokens. To compare how long runs took, read their lifecycle events with `vercel__get_agent_run`. -3. Read each picked run with `vercel__get_agent_run_trace`. A trace can come in pages: while the response has a `later` cursor, fetch the next page. An empty trace doesn't mean the run did nothing. Look for: +3. Read each picked run with `vercel__get_agent_run_trace`. A trace can come in pages: while the response has a `later` cursor, fetch the next page. An empty trace doesn't mean the run did nothing. A trace without tool inputs and outputs still shows which tools ran and how often: skip the checks that need content, and say so in the report. Look for: - a tool call that failed and was retried with the same input - the same tool called several times in one turn, such as paging through a list or a log - a tool output much larger than the answer needed @@ -273,25 +277,25 @@ This one needs no skill: it reads two lists and posts a few lines. Its message s ## Run it -`eve dev` never fires a schedule on its own. It serves a route that fires one by name instead. Start the dev server: +The review reads production runs, and Slack sends replies in the report thread to the deployed agent, so test it in production. Deploy: ```bash [Terminal] -npx eve dev +npx eve deploy ``` -Then, in a second terminal, fire the weekly review: +On Vercel, each eve schedule becomes a [Vercel Schedule](https://vercel.com/docs/schedules) named `eve.` plus the schedule's file name. List them, then fire the weekly review now instead of waiting for Monday: ```bash [Terminal] -curl -X POST http://localhost:2000/eve/v1/dev/schedules/weekly-review +vercel schedules list ``` -The review reads the production runs of your deployed agent, opens its pull requests on `AGENT_REPOSITORY`, and posts the report in the reports channel. Slack sends replies in that thread to the deployed agent, not to `eve dev`, so deploy before you answer it: - ```bash [Terminal] -npx eve deploy +vercel schedules invoke eve.weekly-review ``` -Review the pull requests on GitHub. When the project is connected to the repository, merging one deploys the agent with the change. Otherwise, run `npx eve deploy` again. In the Vercel dashboard, **Settings → Cron Jobs** lists both schedules. +The review opens its pull requests on `AGENT_REPOSITORY` and posts the report in the reports channel. `vercel schedules executions list eve.weekly-review` shows each run, and **Observability → Logs** shows its logs. + +Review the pull requests on GitHub. When the project is connected to the repository, merging one deploys the agent with the change. Otherwise, run `npx eve deploy` again. ## Choose how much the agent does on its own @@ -344,6 +348,61 @@ Update the skill to match: at level 3, "After opening a pull request, call `enab Each level up trades your review for your checks. Move up once the reports and pull requests at the level below have been right for a few weeks, and only as far as your tests can catch a bad change. A prompt that rewrites itself without anyone looking can drift in ways no single change shows, and at level 4 the weekly report is the only place you'd notice. +## Let the review read tool inputs and outputs + +eve decides what a trace records from each session's [audience](https://eve.dev/docs/channels#audience). In production, a public session, such as a public Slack channel, records inputs and outputs. A private or unknown one, such as a direct message or a private channel, records metadata only: which tools ran, when, and for how long, without their inputs and outputs. + +From metadata alone, the review still finds failed runs, slow runs and the same tool called many times in one turn. It can't tell whether a retry used the same input, whether an output was much larger than needed, or whether the agent asked a question its instructions answer. + +To record inputs and outputs for every session, set the trace policy in `agent/instrumentation/otel.ts`: + +```ts [agent/instrumentation/otel.ts] +import { otel } from 'eve/instrumentation/otel' + +export default otel({ + tracePolicy: () => ({ emit: true, recordInputs: true, recordOutputs: true }), +}) +``` + +Agent Runs then holds what people wrote in direct messages and private channels, and every project member with trace access can read it. Recording content also keeps the session's stored run data, which eve otherwise deletes when a private run ends. [OpenTelemetry](https://eve.dev/docs/observability/otel) describes the policy, and [Agent Runs](https://eve.dev/docs/observability/agent-runs#redact-content) shows how to redact content from Agent Runs only. + +## Troubleshooting + +### Every Vercel MCP call fails with `OAuth token request failed` + +Vercel Connect couldn't issue the connector's app token. eve passes the model this generic message, so check the cause from the CLI: + +- `vercel connect list` shows the connector attached to the project. +- When you created the connector, you signed in with an account that can access the agent's project and granted the team that owns it. + +If both hold and Connect reports `invalid_client`, Vercel's token endpoint rejected the connector's app credentials. One tested workaround is a shared grant: every scheduled run and maintainer uses one Connect subject, which a person authorizes once. In the connection, add `createSubject` to the `connect()` call: + +```ts [agent/connections/vercel.ts] +return connect({ + connector: 'vercel/github-agent', + principalType: 'app', + createSubject: () => ({ type: 'user', id: 'self-review', issuer: process.env.AGENT_PROJECT_ID }), +}) +``` + +The token then acts with the Vercel access of the person who authorized the grant. Three constraints apply when you authorize it: + +- The grant belongs to the environment of the OIDC token that started it, so a grant started with your local `VERCEL_OIDC_TOKEN` doesn't work in production. Start it from a production deployment. +- eve never runs a consent flow for an app connection, or in a schedule session, so the agent can't start it for you. Call `startAuthorization('vercel/github-agent', { subject })` from `@vercel/connect` in a production function, with the same subject, and open the URL it returns. +- `vercel connect token --subject app` doesn't work from the CLI, so you can't test an app token before you deploy. + +### Every Vercel MCP call returns `403` + +The grant doesn't include the team that owns the agent's project. Granting team access is a separate step from signing in. Approve team access for the grant through the Vercel MCP's `authorize_team_access` link, signed in to that team. On a team with SAML SSO, that link starts an SSO session request. + +### The review says traces have no tool inputs or outputs + +That's the default for private sessions. See [Let the review read tool inputs and outputs](#let-the-review-read-tool-inputs-and-outputs). + +### A maintainer gets "Only scheduled runs and maintainers can read this agent's runs" + +Their member ID isn't in `MAINTAINERS`, or the project wasn't redeployed after the variable changed. Environment variables apply to new deployments only. + ## FAQ ::accordion diff --git a/examples/eve/README.md b/examples/eve/README.md index afec662..11daebf 100644 --- a/examples/eve/README.md +++ b/examples/eve/README.md @@ -77,6 +77,8 @@ export default githubExtension({ npx eve add channel/slack ``` + The setup picks its own connector name, such as `slack/eve`, so `agent/channels/slack.ts` can name a different connector than `slack/github-agent`. Keep the name it wrote. + 4. Create the GitHub connector, then attach it to the project with its webhooks routed to the agent: ```bash