Add gateway examples for agent frameworks#2059
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (7)
🔗 Linked repositories identifiedCodeRabbit considers these linked repositories for cross-repo context during reviews:
✅ Files skipped from review due to trivial changes (7)
📝 WalkthroughWalkthroughThe AI Gateway landing page now says “large language model (LLM) calls” and links to a new agent-frameworks page. That new page adds shared gateway setup guidance, runnable examples across multiple TypeScript, Python, Go, and .NET agent frameworks, and a closing note listing additional frameworks not shown as gateway snippets. The AI Gateway navigation is expanded to include Overview and Agent Frameworks entries, and related docs links now point to the new Possibly related PRs
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/integrations/agent-frameworks/mastra.md`:
- Line 169: The agent lookup in the Mastra examples uses the wrong identifier,
so update the calls to match the registered id used in the setup code. In the
relevant snippets around the getAgent usage, replace the mismatched weatherAgent
lookup with the registered weather-agent id, and apply the same correction in
the gateway example so both examples resolve the same agent consistently.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 193c5756-4fee-4f61-87dc-68c68039c2b0
📒 Files selected for processing (2)
docs/integrations/agent-frameworks/mastra.mddocs/integrations/agent-frameworks/vercel-ai-sdk.md
🔗 Linked repositories identified
CodeRabbit considers these linked repositories for cross-repo context during reviews:
pydantic/logfire(manual)pydantic/pydantic-ai(manual)pydantic/pydantic(auto-detected)
|
|
||
| async function main() { | ||
| try { | ||
| const result = await mastra.getAgent('weatherAgent').generate('What is the weather in London?'); |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Use the registered agent id here.
Both snippets register the agent as id: 'weather-agent', but getAgent('weatherAgent') looks up a different identifier. Copied code will fail to resolve the agent.
💡 Suggested fix
- const result = await mastra.getAgent('weatherAgent').generate('What is the weather in London?');
+ const result = await mastra.getAgent('weather-agent').generate('What is the weather in London?');Apply the same replacement in the gateway example too.
Also applies to: 291-291
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@docs/integrations/agent-frameworks/mastra.md` at line 169, The agent lookup
in the Mastra examples uses the wrong identifier, so update the calls to match
the registered id used in the setup code. In the relevant snippets around the
getAgent usage, replace the mismatched weatherAgent lookup with the registered
weather-agent id, and apply the same correction in the gateway example so both
examples resolve the same agent consistently.
There was a problem hiding this comment.
3 issues found across 4 files (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="docs/integrations/agent-frameworks/mastra.md">
<violation number="1">
P1: The agent's weather tool won't work: `execute: async ({ context })` destructures `context` from the tool's input data, but the inputSchema defines `{ city }`, so `context` is `undefined` and `context.city` collapses at runtime. The first parameter is the validated input fields directly (`inputData: TSchemaIn`); the execution context is the second parameter. Change to `execute: async ({ city }) => ({ city, tempC: 21 })`.</violation>
<violation number="2">
P2: The example no longer flushes telemetry before exit. Short-lived scripts that make one agent call and exit immediately risk losing all trace data because the OTLP batch exporter may not have sent the spans before the process terminates. Add `await mastra.observability.flush()` before `console.log()` or in a `finally` block, and mention the flush requirement in the Common pitfalls section so readers don't copy a silently broken pattern.</violation>
</file>
<file name="docs/integrations/agent-frameworks/vercel-ai-sdk.md">
<violation number="1">
P1: TypeScript/ESM syntax error: `import` declarations cannot follow a statement. The code block shows `import * as logfire from '...'`, then `logfire.configure(...)`, then more `import { ... } from 'ai'`. This will fail to parse with tsx, ts-node, or any TypeScript compiler. Move all imports to the top of the file before any statements.</violation>
</file>
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/reference/advanced/gateway/agent-frameworks.md`:
- Around line 31-33: The gateway docs use inconsistent environment variable
names between the agent-frameworks page and the gateway index page; choose a
single canonical name and update both references to match, or explicitly
document why `LOGFIRE_GATEWAY_API_KEY` and `PYDANTIC_AI_GATEWAY_API_KEY` differ.
Update the env schema example in the gateway docs and the corresponding mention
in the index page so readers see one consistent gateway API key variable name
throughout.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: b86febdf-a969-4c78-a32e-9f07acabc9fa
📒 Files selected for processing (1)
docs/reference/advanced/gateway/agent-frameworks.md
🔗 Linked repositories identified
CodeRabbit considers these linked repositories for cross-repo context during reviews:
pydantic/logfire(manual)pydantic/pydantic-ai(manual)pydantic/pydantic(auto-detected)
| const envSchema = z.object({ | ||
| LOGFIRE_GATEWAY_API_KEY: z.string(), | ||
| }); |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf 'File outline:\n'
ast-grep outline docs/reference/advanced/gateway/agent-frameworks.md --view expanded || true
printf '\nSearch env var names in logfire docs:\n'
rg -n "LOGFIRE_GATEWAY_API_KEY|PYDANTIC_AI_GATEWAY_API_KEY|GATEWAY_API_KEY" docs . || true
printf '\nRelevant file snippet:\n'
sed -n '1,120p' docs/reference/advanced/gateway/agent-frameworks.mdRepository: pydantic/logfire
Length of output: 10786
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf 'Matches in logfire repo:\n'
rg -n "LOGFIRE_GATEWAY_API_KEY|PYDANTIC_AI_GATEWAY_API_KEY|GATEWAY_API_KEY" .
printf '\nNearby context around the reviewed file:\n'
sed -n '1,120p' docs/reference/advanced/gateway/agent-frameworks.mdRepository: pydantic/logfire
Length of output: 7516
Use one gateway env var name across the docs. This page uses LOGFIRE_GATEWAY_API_KEY, while docs/reference/advanced/gateway/index.md still uses PYDANTIC_AI_GATEWAY_API_KEY; pick one and update both pages, or call out why they differ.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@docs/reference/advanced/gateway/agent-frameworks.md` around lines 31 - 33,
The gateway docs use inconsistent environment variable names between the
agent-frameworks page and the gateway index page; choose a single canonical name
and update both references to match, or explicitly document why
`LOGFIRE_GATEWAY_API_KEY` and `PYDANTIC_AI_GATEWAY_API_KEY` differ. Update the
env schema example in the gateway docs and the corresponding mention in the
index page so readers see one consistent gateway API key variable name
throughout.
Source: Linked repositories
There was a problem hiding this comment.
1 issue found across 4 files (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="docs/reference/advanced/gateway/agent-frameworks.md">
<violation number="1" location="docs/reference/advanced/gateway/agent-frameworks.md:235">
P1: The LlamaIndex.TS example imports `agent` from `@llamaindex/workflow`, but this package does not appear to exist on npm and no known LlamaIndex.TS API exports an `agent` function. This snippet will not compile. The standard LlamaIndex.TS agent API uses `OpenAIAgent` from the main `llamaindex` package with `agent.chat()`, not `agent()` + `.run()`.</violation>
</file>
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
|
|
||
| ```typescript title="llamaindex-ts-gateway.mts" | ||
| import { openai } from '@llamaindex/openai'; | ||
| import { agent } from '@llamaindex/workflow'; |
There was a problem hiding this comment.
P1: The LlamaIndex.TS example imports agent from @llamaindex/workflow, but this package does not appear to exist on npm and no known LlamaIndex.TS API exports an agent function. This snippet will not compile. The standard LlamaIndex.TS agent API uses OpenAIAgent from the main llamaindex package with agent.chat(), not agent() + .run().
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At docs/reference/advanced/gateway/agent-frameworks.md, line 235:
<comment>The LlamaIndex.TS example imports `agent` from `@llamaindex/workflow`, but this package does not appear to exist on npm and no known LlamaIndex.TS API exports an `agent` function. This snippet will not compile. The standard LlamaIndex.TS agent API uses `OpenAIAgent` from the main `llamaindex` package with `agent.chat()`, not `agent()` + `.run()`.</comment>
<file context>
@@ -126,3 +130,446 @@ const mastra = new Mastra({
+
+```typescript title="llamaindex-ts-gateway.mts"
+import { openai } from '@llamaindex/openai';
+import { agent } from '@llamaindex/workflow';
+import { z } from 'zod';
+
</file context>
There was a problem hiding this comment.
3 issues found across 7 files (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="docs/reference/advanced/gateway/index.md">
<violation number="1" location="docs/reference/advanced/gateway/index.md:165">
P2: Absolute link points to a path that doesn't exist in the docs site structure. The page is at `/logfire/reference/advanced/gateway/agent-frameworks/`, not `/logfire/manage/ai-gateway/agent-frameworks/`. With `absolute_links: warn` in mkdocs.yml this will produce a build warning. Either use a relative markdown link (`./agent-frameworks.md`) or the correct absolute path.</violation>
</file>
<file name="docs/comparisons/index.md">
<violation number="1" location="docs/comparisons/index.md:55">
P1: The updated AI gateway link `/logfire/manage/ai-gateway/` points to a URL path that doesn't correspond to any page in the documentation. The gateway overview is located at `docs/reference/advanced/gateway/index.md` (nav slug `reference/advanced/gateway/index`), which would be served at `/logfire/reference/advanced/gateway/` on the deployed site. This change introduces a broken link that will 404 for readers. Update the link to the correct absolute path, e.g. `/logfire/reference/advanced/gateway/`.</violation>
</file>
<file name="docs/faq.md">
<violation number="1" location="docs/faq.md:53">
P2: Link targets `/logfire/manage/ai-gateway/` but no content exists at that path — it's a production-site URL, not a local doc reference. The rest of the gateway docs use relative paths (`reference/advanced/gateway/index.md`, etc.). Use a relative path like `reference/advanced/gateway/index.md` to match the mkdocs nav structure and work in local builds.</violation>
</file>
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
| - **Want exceptional Python, TS/JS, Rust support** - While also supporting other languages via OTel | ||
| - **Want evals both ways** - [code-first evals with pydantic-evals](https://pydantic.dev/docs/logfire/evaluate/datasets/?utm_source=comparison_docs) that test any Python function, plus a [web UI for datasets, experiments, and live production monitoring](https://pydantic.dev/docs/logfire/evaluate/evals/?utm_source=comparison_docs) | ||
| - **Want the full AI engineering loop in one place** - [prompt management](https://pydantic.dev/docs/logfire/prompt-management/?utm_source=comparison_docs), a playground, and an [AI gateway](../reference/advanced/gateway/index.md) with key management and spending controls, next to your traces | ||
| - **Want the full AI engineering loop in one place** - [prompt management](https://pydantic.dev/docs/logfire/prompt-management/?utm_source=comparison_docs), a playground, and an [AI gateway](/logfire/manage/ai-gateway/) with key management and spending controls, next to your traces |
There was a problem hiding this comment.
P1: The updated AI gateway link /logfire/manage/ai-gateway/ points to a URL path that doesn't correspond to any page in the documentation. The gateway overview is located at docs/reference/advanced/gateway/index.md (nav slug reference/advanced/gateway/index), which would be served at /logfire/reference/advanced/gateway/ on the deployed site. This change introduces a broken link that will 404 for readers. Update the link to the correct absolute path, e.g. /logfire/reference/advanced/gateway/.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At docs/comparisons/index.md, line 55:
<comment>The updated AI gateway link `/logfire/manage/ai-gateway/` points to a URL path that doesn't correspond to any page in the documentation. The gateway overview is located at `docs/reference/advanced/gateway/index.md` (nav slug `reference/advanced/gateway/index`), which would be served at `/logfire/reference/advanced/gateway/` on the deployed site. This change introduces a broken link that will 404 for readers. Update the link to the correct absolute path, e.g. `/logfire/reference/advanced/gateway/`.</comment>
<file context>
@@ -52,7 +52,7 @@ Logfire is a great fit when you:
- **Want exceptional Python, TS/JS, Rust support** - While also supporting other languages via OTel
- **Want evals both ways** - [code-first evals with pydantic-evals](https://pydantic.dev/docs/logfire/evaluate/datasets/?utm_source=comparison_docs) that test any Python function, plus a [web UI for datasets, experiments, and live production monitoring](https://pydantic.dev/docs/logfire/evaluate/evals/?utm_source=comparison_docs)
-- **Want the full AI engineering loop in one place** - [prompt management](https://pydantic.dev/docs/logfire/prompt-management/?utm_source=comparison_docs), a playground, and an [AI gateway](../reference/advanced/gateway/index.md) with key management and spending controls, next to your traces
+- **Want the full AI engineering loop in one place** - [prompt management](https://pydantic.dev/docs/logfire/prompt-management/?utm_source=comparison_docs), a playground, and an [AI gateway](/logfire/manage/ai-gateway/) with key management and spending controls, next to your traces
- **Prefer SQL-based querying** - Familiar PostgreSQL syntax over proprietary query languages
- **Value simple, predictable pricing** - $2/million spans, scales to billions of spans per month
</file context>
| - **Want the full AI engineering loop in one place** - [prompt management](https://pydantic.dev/docs/logfire/prompt-management/?utm_source=comparison_docs), a playground, and an [AI gateway](/logfire/manage/ai-gateway/) with key management and spending controls, next to your traces | |
| - **Want the full AI engineering loop in one place** - [prompt management](https://pydantic.dev/docs/logfire/prompt-management/?utm_source=comparison_docs), a playground, and an [AI gateway](/logfire/reference/advanced/gateway/) with key management and spending controls, next to your traces |
|
|
||
| ## See also | ||
|
|
||
| - [Using the gateway with agent frameworks](/logfire/manage/ai-gateway/agent-frameworks/) — route framework model calls through the gateway. |
There was a problem hiding this comment.
P2: Absolute link points to a path that doesn't exist in the docs site structure. The page is at /logfire/reference/advanced/gateway/agent-frameworks/, not /logfire/manage/ai-gateway/agent-frameworks/. With absolute_links: warn in mkdocs.yml this will produce a build warning. Either use a relative markdown link (./agent-frameworks.md) or the correct absolute path.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At docs/reference/advanced/gateway/index.md, line 165:
<comment>Absolute link points to a path that doesn't exist in the docs site structure. The page is at `/logfire/reference/advanced/gateway/agent-frameworks/`, not `/logfire/manage/ai-gateway/agent-frameworks/`. With `absolute_links: warn` in mkdocs.yml this will produce a build warning. Either use a relative markdown link (`./agent-frameworks.md`) or the correct absolute path.</comment>
<file context>
@@ -162,6 +162,6 @@ Or run just the proxy and configure a tool manually with `logfire gateway serve`
## See also
-- [Using the gateway with agent frameworks](./agent-frameworks.md) — route framework model calls through the gateway.
+- [Using the gateway with agent frameworks](/logfire/manage/ai-gateway/agent-frameworks/) — route framework model calls through the gateway.
- [Prompt Management: Access and Prerequisites](../prompt-management/plan-requirements.md) — prompt runs execute through the gateway and spend gateway budget.
- [Cost & Usage](../../../logfire-costs.md) — plan tiers and how usage is billed.
</file context>
| - [Using the gateway with agent frameworks](/logfire/manage/ai-gateway/agent-frameworks/) — route framework model calls through the gateway. | |
| - [Using the gateway with agent frameworks](/logfire/reference/advanced/gateway/agent-frameworks/) — route framework model calls through the gateway. |
| - [Evals](guides/web-ui/evals.md): datasets, experiments, and [live production monitoring](guides/web-ui/live-evals.md) in the web UI, powered by code-first [pydantic-evals](https://github.com/pydantic/pydantic-evals) | ||
| - [Prompt management](reference/advanced/prompt-management/index.md) with versioning, labeled rollouts, and a playground | ||
| - An [AI Gateway](reference/advanced/gateway/index.md) with unified key management, spending limits, and provider failover | ||
| - An [AI Gateway](/logfire/manage/ai-gateway/) with unified key management, spending limits, and provider failover |
There was a problem hiding this comment.
P2: Link targets /logfire/manage/ai-gateway/ but no content exists at that path — it's a production-site URL, not a local doc reference. The rest of the gateway docs use relative paths (reference/advanced/gateway/index.md, etc.). Use a relative path like reference/advanced/gateway/index.md to match the mkdocs nav structure and work in local builds.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At docs/faq.md, line 53:
<comment>Link targets `/logfire/manage/ai-gateway/` but no content exists at that path — it's a production-site URL, not a local doc reference. The rest of the gateway docs use relative paths (`reference/advanced/gateway/index.md`, etc.). Use a relative path like `reference/advanced/gateway/index.md` to match the mkdocs nav structure and work in local builds.</comment>
<file context>
@@ -50,7 +50,7 @@ Yes: Logfire is _built_ for AI observability, and it's better at it because it s
- [Evals](guides/web-ui/evals.md): datasets, experiments, and [live production monitoring](guides/web-ui/live-evals.md) in the web UI, powered by code-first [pydantic-evals](https://github.com/pydantic/pydantic-evals)
- [Prompt management](reference/advanced/prompt-management/index.md) with versioning, labeled rollouts, and a playground
-- An [AI Gateway](reference/advanced/gateway/index.md) with unified key management, spending limits, and provider failover
+- An [AI Gateway](/logfire/manage/ai-gateway/) with unified key management, spending limits, and provider failover
**Better debugging:** When your AI agent fails, you don't just see the LLM error. You see the database timeout that caused it, the API rate limit that preceded it, and the user request that started it all.
</file context>
| - An [AI Gateway](/logfire/manage/ai-gateway/) with unified key management, spending limits, and provider failover | |
| - An [AI Gateway](reference/advanced/gateway/index.md) with unified key management, spending limits, and provider failover |
Summary:
Checks: