DEV Community

Muhammad Mairaj
Muhammad Mairaj

Posted on

The shortest AI agent you can build

We're going to build an AI agent that uses GPT-5. We'll use agent primitive by Langbase.

The agent works as a runtime LLM agent. You can specify all parameters at runtime and get the response from the agent. Agent uses Langbase's unified LLM API to provide a consistent interface for interacting with 600+ LLMs across all the top LLM providers.

See the list of supported models and providers.

Okay, let's get to building! 🚀

Installation

Start by installing the Langbase SDK (comes in both TypeScript and Python).

npm install langbase
Enter fullscreen mode Exit fullscreen mode

Langbase API Key

Every request you send to Langbase needs an API key. You need to generate your API key by following these steps:

  1. Sign up at Langbase.com
  2. From the sidebar, click on the API keys
  3. From here, you can create a new API key. For more details, follow this guide

Create a .env file and place the Langbase API key like this:

LANGBASE_API_KEY=your_langbase_api_key
Enter fullscreen mode Exit fullscreen mode

Another environment variable you need is for the LLM model you decide to use. In this example, we are using OpenAI's GPT-5. So add the LLM API Key like this:

LLM_API_KEY=your_openai_api_key
Enter fullscreen mode Exit fullscreen mode

Setting Up the Code

Next, create an index.ts file and import the necessary packages.

import { Langbase } from 'langbase';
import 'dotenv/config';
Enter fullscreen mode Exit fullscreen mode

Let's initialize Langbase:

const langbase = new Langbase({
    apiKey: process.env.LANGBASE_API_KEY!
});
Enter fullscreen mode Exit fullscreen mode

The AI Agent Code

Finally, the code for the AI agent. It might be the shortest AI agent ever. Here it is:

const {output} = await langbase.agent.run({
    model: 'openai:gpt-5-mini-2025-08-07',
    instructions: 'You are a helpful AI Agent.',
    input: 'Who is an AI Engineer?',
    apiKey: process.env.LLM_API_KEY!,
    stream: false,
});

console.log(output)
Enter fullscreen mode Exit fullscreen mode

Running Your Agent

Finally, run your code:

npx tsx index.ts
Enter fullscreen mode Exit fullscreen mode

That's It!

That's like 5–6 lines of code. The code is pretty much the same in Python too.

You can dynamically modify:

  • The prompt
  • The model
  • The system prompt (instructions param)
  • Get the agent to stream the output

It's up to you! Langbase supports 600+ AI models. This includes open source models like:

  • Kimi K2
  • DeepSeek R1
  • Grok 4
  • And many more

What are you waiting for? Build your AI agent today!

Top comments (0)