Bugs in Agent Builder Exported Code (TypeScript) — Template String Escaping, State Typing, and Property Naming

While testing exported code from OpenAI’s Agent Builder, I found a few consistent issues in the TypeScript export version.
These cause compile or runtime errors unless manually patched.


:lady_beetle: 1. Template string escaping issue

When using a single backtick for code blocks (`) inside a message or prompt string, it’s not being escaped properly.
The generated code wraps the whole message inside backticks, but doesn’t escape the inner ones — leading to invalid syntax.

Example:

const message = `Here’s an inline code block: `const x = 10`;`;

Should be:

const message = `Here’s an inline code block: \`const x = 10\`;`;

:right_arrow: Fix: Escape all backticks inside prompt/message text using ``` before wrapping the string.


:puzzle_piece: 2. Type assertion issue in state initialization

Even when state variables are defined as strings with null defaults, the export omits proper type assertions.
This results in a compile-time error when assigning or checking values later.

Currently exported:

const state = {
  preferred_language: null,
  selected_role: null
};

Should be:

const state: {
  preferred_language: string | null;
  selected_role: string | null;
} = {
  preferred_language: null,
  selected_role: null
};

:right_arrow: Fix: Add explicit typing for all nullable state keys in exported TypeScript.


:globe_with_meridians: 3. Naming mismatch in webSearchTool filters

In the exported code, webSearchTool uses allowed_domains instead of the correct allowedDomains.

Current:

filters: {
  allowed_domains: ["example.com"]
}

Expected:

filters: {
  allowedDomains: ["example.com"]
}

:right_arrow: Fix: Use allowedDomains consistently (camelCase) to match the API schema and runtime expectations.


:receipt: Summary

# Issue Impact Suggested Fix
1 Backtick escaping Syntax error in prompts Escape backticks before wrapping
2 State typing TypeScript compile errors Add explicit type declarations
3 allowed_domains Invalid property name Change to allowedDomains

:white_check_mark: Environment

  • Export Format: TypeScript
  • Runtime: Node.js 20+
  • Observed In: Multiple exported agents