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 …


This content originally appeared on DEV Community and was authored by Muhammad Mairaj

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

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

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

Setting Up the Code

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

import { Langbase } from 'langbase';
import 'dotenv/config';

Let's initialize Langbase:

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

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)

Running Your Agent

Finally, run your code:

npx tsx index.ts

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!


This content originally appeared on DEV Community and was authored by Muhammad Mairaj


Print Share Comment Cite Upload Translate Updates
APA

Muhammad Mairaj | Sciencx (2025-09-18T20:41:27+00:00) The shortest AI agent you can build. Retrieved from https://www.scien.cx/2025/09/18/the-shortest-ai-agent-you-can-build/

MLA
" » The shortest AI agent you can build." Muhammad Mairaj | Sciencx - Thursday September 18, 2025, https://www.scien.cx/2025/09/18/the-shortest-ai-agent-you-can-build/
HARVARD
Muhammad Mairaj | Sciencx Thursday September 18, 2025 » The shortest AI agent you can build., viewed ,<https://www.scien.cx/2025/09/18/the-shortest-ai-agent-you-can-build/>
VANCOUVER
Muhammad Mairaj | Sciencx - » The shortest AI agent you can build. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/09/18/the-shortest-ai-agent-you-can-build/
CHICAGO
" » The shortest AI agent you can build." Muhammad Mairaj | Sciencx - Accessed . https://www.scien.cx/2025/09/18/the-shortest-ai-agent-you-can-build/
IEEE
" » The shortest AI agent you can build." Muhammad Mairaj | Sciencx [Online]. Available: https://www.scien.cx/2025/09/18/the-shortest-ai-agent-you-can-build/. [Accessed: ]
rf:citation
» The shortest AI agent you can build | Muhammad Mairaj | Sciencx | https://www.scien.cx/2025/09/18/the-shortest-ai-agent-you-can-build/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.