[Jens Neuse](/content/people/jens-neuse/index.html)  
CEO & Co-Founder at WunderGraph  
July 12, 2023·14min read  
Last updated on July 18, 2026

Archive Notice  
This article is archived and no longer maintained. It describes an earlier version of WunderGraph's Agent SDK and TypeScript Operations, which are no longer part of the current product. The examples and implementation details may not work as described. For current documentation and guidance, see [WunderGraph Documentation](/content/cosmo/index.html).

## State of GraphQL Federation 2026

How are teams governing schema changes, handling production traffic, and measuring Federation success? Share your experience and get early access to the full report. For every valid survey completed, we'll donate $30 to [UNICEF](https://www.unicef.org/).

### Examples

#### Example 1: AI Agent creation with OpenAI

Here's a simple example that shows how we can use OpenAI to create an Agent that can call multiple APIs and return structured data (JSON) conforming to our defined API schema.

```typescript
// .wundergraph/operations/openai/GetWeatherByCountry.ts
export default createOperation.query({
  input: z.object({
    country: z.string(),
  }),
  description:
    'This operation returns the weather of the capital of the given country',
  handler: async ({ input, openAI, log }) => {
    const parsed = await openAI.parseUserInput({
      userInput: input.country,
      schema: z.object({
        country: z.string().nonempty(),
      }),
    })
    const agent = openAI.createAgent({
      functions: [{ name: 'CountryByCode' }, { name: 'weather/GetCityByName' }],
      structuredOutputSchema: z.object({
        city: z.string(),
        country: z.string(),
        temperature: z.number(),
      }),
    })
    return agent.execWithPrompt({
      prompt: `What's the weather like in the capital of ${parsed.country}?`,
    })
  },
})
```

#### Example 2: OpenAI enhanced API

How about extracting meta data from a website and exposing the functionality as a JSON API? Sounds simple enough, right?

```typescript
// .wundergraph/operations/openai/GetWebsiteInfo.ts
export default createOperation.query({
  input: z.object({
    url: z.string(),
  }),
  description:
    'This operation returns the title, description, h1 and a summary of the given website',
  handler: async ({ input, openAI, log }) => {
    const agent = openAI.createAgent({
      model: 'gpt-3.5-turbo-16k-0613',
      functions: [
        { name: 'web/load_url', pagination: { pageSize: 1024 * 15, maxPages: 3 } },
        { name: 'openai/summarize_url_content' },
      ],
      structuredOutputSchema: z.object({
        title: z.string(),
        description: z.string(),
        h1: z.string(),
        summary: z.string(),
      }),
    })
    return agent.execWithPrompt({
      prompt: `Load the content of the URL: ${url}
                You're a HTML parser. Your job is to extract the title, description and h1 from the HTML.
                Do not include the HTML tags in the result.
                Don't change the content, just extract the information.

Once this is done, add a summary of the website.
                `,
    })
  },
})
```

## The Problem: Building AI enhanced APIs and Agents is challenging

### What are AI enhanced APIs?
An AI enhanced API is an API that accepts an input in a predefined format and returns structured data (e.g. JSON), allowing it to be described using a schema (e.g. OpenAPI, GraphQL, etc.).

### What are AI Agents?
An AI Agent is a dialog between a large language model (e.g. GPT-3) and a computer program that is capable of performing a task.

### Challenges

1. **LLMs don't usually return structured data, but plain text**
2. **Prompt Injection: We cannot trust user input**
3. **Pagination & Batching: LLMs can only process a limited amount of tokens at once**
4. **Composing Agents: We need to be able to compose Agents**
5. **LLMs like OpenAI cannot call external APIs and Databases directly**

## The Solution: The WunderGraph OpenAI Integration / Agent SDK

## Getting started with the WunderGraph Agent SDK
If you need more info on how to get started with WunderGraph and OpenAI, check out the OpenAI Integration Docs.

## Conclusion
In this article, we've learned how to use the WunderGraph Agent SDK to create AI Agents that can be used to integrate any API into your AI Agent.

I’d love to hear your thoughts on this topic, so feel free to reach out to me on [Twitter](https://twitter.com/TheWorstFounder) or join our [Discord server](/content/discord/index.html) to chat about it.
