Skip to content

OpenAI agent ts docs 1934#2210

Open
anastasiaguspan wants to merge 7 commits intomainfrom
openai-agent-ts-docs-1934
Open

OpenAI agent ts docs 1934#2210
anastasiaguspan wants to merge 7 commits intomainfrom
openai-agent-ts-docs-1934

Conversation

@anastasiaguspan
Copy link
Contributor

@anastasiaguspan anastasiaguspan commented Mar 2, 2026

Description

Documentation for TypeScript SDK: OpenAI agents Integration

I have tested this 'getting started' code example but it does require 'await weave.instrumentOpenAIAgents();' to work.

if that's accurate, Proposing we remove these lines under Section "manual instrumentation":
In most cases, automatic instrumentation handles everything. If you need manual control, for example when using dynamic imports or bundlers that bypass module hooks, you can call instrumentOpenAIAgents() explicitly:

import * as weave from "weave";

await weave.init("openai-agents");
await weave.instrumentOpenAIAgents();

Testing

  • [ x] Local build succeeds without errors (mint dev)
  • [ ]x Local link check succeeds without errors (mint broken-links)
  • PR tests succeed

Related issues

@github-actions
Copy link
Contributor

github-actions bot commented Mar 2, 2026

📚 Mintlify Preview Links

🔗 View Full Preview

📝 Changed (3 total)

📄 Pages (2)

File Preview
weave/guides/integrations/js.mdx Js
weave/guides/integrations/openai_agents.mdx Openai Agents
⚙️ Other (1)
File
docs.json

🤖 Generated automatically when Mintlify deployment succeeds
📍 Deployment: 17d5798 at 2026-03-13 17:53:13 UTC

@github-actions
Copy link
Contributor

github-actions bot commented Mar 2, 2026

🔗 Link Checker Results

All links are valid!

No broken links were detected.

Checked against: https://wb-21fd5541-openai-agent-ts-docs-1934.mintlify.app

Copy link
Contributor

@chance-wnb chance-wnb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much Anastasia. Overall this looks great! 👍 I thought about some minor details. Can you help me verify a few things please?

In the following code sample, an OpenAI Agent is created and integrated with Weave for traceability. First, update `your-team-name/your-project-name` in the Weave project initialization to real values. A `get_weather` tool is defined that returns a sample weather report. An agent named `Hello world` is configured with basic instructions and access to the weather tool. The main function runs the agent with a sample input (`What's the weather in Tokyo?`) and outputs the final response.

```typescript
import * as weave from "weave";
Copy link
Contributor

@chance-wnb chance-wnb Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the CommonJS way, since we are not relying on pre-loader, if we move import * as weave from "weave"; after import { Agent, run, tool } from "@openai/agents"; (which means the import of @openai/agents runs first), does it still work I wonder?

If it doesn't, and for some reason users are unable to put import * as weave from "weave"; first. We can suggest them to manually patch in such a situtation.

If it still works, then we are good!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in cjs, we don't use import, so assuming for cjs you meant
const weave = require("weave");
const { Agent, run, tool } = require("@openai/agents");

changed to
const { Agent, run, tool } = require("@openai/agents");
const weave = require("weave");

no, it didn't work.
So i will call this ordering out specifically, good catch. Tho calling this out might be a little confusing since the import code is different from the example, i'll see what I can do
(just to be sure i did test this for the esm version and it was fine)

Copy link
Contributor

@chance-wnb chance-wnb Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. what I said earlier is confusing, let me clarify: regardless of whether it is CJS or ESM, people always write it as:

import * as weave from "weave";
import { Agent, run, tool } from "@openai/agents"; 

as TypeScript. This looks identical like ESM, but it is TypeScript :) It just happens that TypeScript uses the modern ESM syntax.

Eventually, under CJS config, it will be configured to:

const weave = require("weave");
const { Agent, run, tool } = require("@openai/agents");

…tup, clarified import ordering for CommonJS agent integration
In the following code sample, an OpenAI Agent is created and integrated with Weave for traceability. First, update `your-team-name/your-project-name` in the Weave project initialization to real values. A `get_weather` tool is defined that returns a sample weather report. An agent named `Hello world` is configured with basic instructions and access to the weather tool. The main function runs the agent with a sample input (`What's the weather in Tokyo?`) and outputs the final response.

```typescript
import * as weave from "weave";
Copy link
Contributor

@chance-wnb chance-wnb Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. what I said earlier is confusing, let me clarify: regardless of whether it is CJS or ESM, people always write it as:

import * as weave from "weave";
import { Agent, run, tool } from "@openai/agents"; 

as TypeScript. This looks identical like ESM, but it is TypeScript :) It just happens that TypeScript uses the modern ESM syntax.

Eventually, under CJS config, it will be configured to:

const weave = require("weave");
const { Agent, run, tool } = require("@openai/agents");


The example code on this page uses ESM syntax. In CommonJS projects, the equivalent import statement is:
```typescript lines
const weave = require("weave");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so here maybe you also want to mention the typescript syntax as well:

import * as weave from "weave";
import { Agent, run, tool } from "@openai/agents"; 

and with CommonJS configuration, the order of that two import statements(which will be translated to require() in compiled code) matters.

Copy link
Contributor

@chance-wnb chance-wnb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much for the due diligence and attention to every detail! It is much appreciated. Great job!

- **`target: "es2022"`** *(Recommended)* — Emits modern JavaScript compatible with recent Node.js versions.
For details on this compiler option, see [TypeScript - Target](https://www.typescriptlang.org/tsconfig/#target).

- **`verbatimModuleSyntax: false`** — Allows ESM-style `import`/`export` syntax in source files while emitting CommonJS output.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: in my opinion, this doesn't seem to be a commonly-seen option. with its default value being false, we probably don't need to mention it. So the simpler the user's config is, the better.

Since tsconfig is such a huge topic, our doc is not the go-to place for every details, as long as we bring something basic that works, we already fulfill our limited liability :)

Just my two cents, and it is a nit-picky comment. I will leave it to your decision.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants