Saturday, September 5, 2026

Specification Engineering: The New Skill After Prompt Engineering

 

Specification Engineering: The New Skill After Prompt Engineering

For the past few years, prompt engineering has been one of the most talked-about skills in artificial intelligence. People learned how to write better instructions for AI systems to generate text, images, code, analysis, and ideas.

But AI is changing quickly.

Modern AI systems are becoming capable of handling much more than a single prompt. AI agents can reason through multi-step tasks, use tools, interact with software, generate code, review their own work, and complete complex workflows.

As AI becomes more capable, simply knowing how to write a clever prompt may no longer be enough.

This is where specification engineering is becoming increasingly important.

What Is Specification Engineering?

Specification engineering is the practice of creating clear, structured, detailed requirements that define what an AI system, software application, agent, or automated workflow should accomplish.

Think of the difference between these two instructions:

"Build me a website for my business."

and:

"Build a responsive business website with five pages. The homepage should contain a hero section, services, customer testimonials, and a contact form. Use a mobile-first layout, accessible color contrast, semantic HTML, fast-loading assets, and clear navigation. The contact form should validate email addresses and display an error message when required fields are missing."

The second instruction is closer to a specification.

Prompt engineering focuses heavily on how to ask AI for something.

Specification engineering focuses on defining exactly what should be built, what constraints apply, how success will be measured, and what the final result should contain.

That distinction becomes extremely important when AI is doing substantial amounts of the work.

Why Prompt Engineering Is Not Enough

A prompt can be excellent and still produce an unsuitable result.

Imagine asking an AI coding agent:

"Create an expense-tracking application."

The AI might generate an impressive application. But important questions remain unanswered.

Should users have accounts?

Should expenses be categorized?

Should the application support multiple currencies?

Should data be stored locally or remotely?

What happens when a user enters invalid information?

Should users be able to export transactions?

What security requirements apply?

What should the interface look like on a smartphone?

Without answers, the AI has to guess.

And AI-generated guesses can create inconsistent or unexpected results.

Specification engineering attempts to reduce that ambiguity.

Specification Engineering Is About Removing Ambiguity

One of the biggest challenges in AI-assisted development is ambiguity.

Humans can sometimes understand incomplete instructions because they have context. AI systems, however, need enough information to determine what outcome is expected.

A good specification can define:

  • Goal — What needs to be achieved?
  • Scope — What is included and excluded?
  • Inputs — What information is provided?
  • Outputs — What should be produced?
  • Constraints — What rules must be followed?
  • Dependencies — What systems or tools are required?
  • Edge cases — What happens when something goes wrong?
  • Acceptance criteria — How do we know the result is correct?

This turns a vague request into something much closer to an engineering blueprint.

The Rise of AI Agents Makes Specifications More Important

AI agents are changing the relationship between humans and software.

Instead of asking an AI to generate a small piece of code, developers can increasingly give an agent a larger objective and allow it to plan and execute multiple steps.

For example:

"Create an online bookstore."

An agent might interpret this as a request to create a database, backend, frontend, authentication system, search functionality, shopping cart, payment integration, administration dashboard, and testing system.

The bigger the task, the more dangerous ambiguity becomes.

A specification gives the agent a map.

Instead of telling an AI exactly which line of code to write, the human defines the desired system and its boundaries.

Specification Engineering Is Similar to Writing a Contract

A useful way to think about specification engineering is to compare it with a contract.

A contract doesn't simply say:

"Do good work."

It defines responsibilities, expectations, conditions, and outcomes.

Similarly, an AI specification should make expectations explicit.

For example:

Objective

Build a personal finance application.

Required features

  • User registration
  • Expense tracking
  • Income tracking
  • Categories
  • Monthly reports
  • CSV export

Constraints

  • Responsive design
  • Secure authentication
  • No unnecessary third-party tracking
  • Accessible interface

Acceptance criteria

  • Users can create and delete transactions.
  • Monthly totals update automatically.
  • Invalid entries generate understandable error messages.
  • Exported CSV files contain all transaction fields.

This gives an AI system considerably more information to work with.

Specifications Can Include Examples

Examples are particularly powerful.

Suppose you want an AI to create a data-processing system.

Instead of simply describing the expected behavior, you can provide:

Input:

{"price":100,"quantity":2}

Expected output:

{"total":200}

Then provide an edge case:

Input:

{"price":100,"quantity":0}

Expected output:

{"total":0}

Examples help establish the intended behavior without requiring a lengthy explanation of every implementation detail.

Acceptance Criteria Are the Secret Weapon

One of the most valuable parts of specification engineering is acceptance criteria.

Acceptance criteria answer a simple question:

How will we decide whether the AI's work is actually finished?

For example:

The login system is complete when a registered user can successfully log in with valid credentials, invalid credentials are rejected, passwords are never stored in plain text, and the system provides an appropriate error message after a failed attempt.

This is much more useful than:

"Build a secure login system."

The first statement provides something that can be tested.

Specifications Should Not Dictate Everything

There is an important balance.

A specification should be detailed enough to eliminate important ambiguity, but it doesn't necessarily need to dictate every implementation decision.

For example, you might tell an AI:

"The application must respond to API requests within the defined performance target."

You don't necessarily need to tell it which internal function should be used.

This leaves room for the AI or developer to choose an appropriate implementation.

In other words:

Specify the outcome and constraints, not every keystroke.

Specification Engineering and Software Development

This emerging skill is particularly relevant to software developers.

AI coding tools can already generate substantial amounts of code. As these tools become more capable, the developer's role can shift from writing every function manually toward:

design → specification → delegation → evaluation → refinement

The developer becomes increasingly responsible for deciding what should be built and determining whether the generated result actually satisfies the requirements.

That doesn't make programming knowledge irrelevant.

Quite the opposite.

Understanding architecture, databases, APIs, security, testing, and software design makes it easier to create better specifications and recognize flawed AI-generated implementations.

How to Learn Specification Engineering

You don't need a special degree to start.

Begin by taking ordinary requests and making them more precise.

Instead of:

"Create a mobile app."

Write:

  1. Purpose
  2. Target users
  3. Core features
  4. User workflows
  5. Data requirements
  6. Interface requirements
  7. Technical constraints
  8. Security requirements
  9. Error handling
  10. Acceptance criteria

Then give the specification to an AI system and evaluate the result.

The next step is learning how to write testable requirements.

If a requirement cannot be evaluated, it may still be too vague.

The Future: From Prompt Engineers to Specification Engineers?

Prompt engineering isn't disappearing. Good prompting will remain useful.

But the role of humans working with AI may become broader.

As AI systems move from simple chatbots toward coding agents, autonomous workflows, and AI-powered development environments, humans increasingly need to communicate objectives, constraints, context, and success conditions.

That's essentially the territory of specification engineering.

The future may not belong to people who simply know the perfect prompt.

It may belong to people who can take a vague idea and turn it into a clear, testable specification that an AI system can execute reliably.

Final Thoughts

Prompt engineering taught people how to communicate effectively with AI.

Specification engineering takes that idea to the next level.

Instead of concentrating only on the wording of an individual prompt, it focuses on defining the complete problem: what needs to be created, why it is needed, what constraints exist, what edge cases matter, and how success will be measured.

As AI agents become capable of completing increasingly complex tasks, this skill could become extremely valuable for developers, product managers, entrepreneurs, designers, and anyone building with AI.

The most important question may gradually change from:

"What prompt should I write?"

to:

"What exactly do I want the AI to build, and how will I know it built it correctly?"

That is the heart of specification engineering.

Nine Simple Open-Source Tools That Can Replace the Entire Adobe Suite

 

9 Simple Open-Source Tools That Can Replace the Entire Adobe Suite

Adobe has built one of the most recognizable creative software ecosystems in the world. Photoshop, Illustrator, Premiere Pro, After Effects, InDesign, Audition, Lightroom, and Acrobat are widely used by designers, photographers, video editors, students, and businesses.

However, the Adobe ecosystem can become expensive, especially for individuals and small teams. The good news is that the open-source community has created powerful alternatives that cover almost every major creative workflow.

You do not necessarily need a single application that copies Adobe feature-for-feature. Instead, a combination of specialized open-source tools can replace much of what the Adobe Creative Cloud ecosystem offers.

Here are nine simple open-source tools worth exploring.

1. GIMP — A Photoshop Alternative

GIMP, short for GNU Image Manipulation Program, is one of the most established open-source creative applications.

It is primarily designed for image editing and can handle tasks such as photo retouching, cropping, color correction, masking, compositing, and graphic design.

Photoshop users will find familiar concepts such as layers, selections, brushes, filters, and paths.

GIMP is particularly useful for photographers, bloggers, students, and designers who need serious image-editing capabilities without paying for a subscription.

Best replacement: Adobe Photoshop

2. Inkscape — A Free Illustrator Replacement

When your work involves logos, icons, illustrations, diagrams, or scalable graphics, Inkscape is one of the best open-source options.

Unlike pixel-based editors, Inkscape focuses on vector graphics. Vector artwork can be resized without losing quality, making it ideal for logos and print designs.

It supports SVG and provides tools for drawing shapes, manipulating paths, creating text, and building complex illustrations.

For someone who mainly uses Illustrator for basic vector work, Inkscape can be a surprisingly capable alternative.

Best replacement: Adobe Illustrator

3. Krita — Digital Painting and Illustration

Krita is an open-source painting application designed with artists in mind.

Its strongest area is digital painting. It provides customizable brushes, layers, stabilizers, animation capabilities, color-management features, and tools for creating illustrations and concept art.

Artists who previously relied on Photoshop for painting may find Krita more focused and comfortable for creative drawing.

It is also useful for comics, storyboards, textures, and character artwork.

Best replacement: Photoshop for digital painting and illustration

4. Kdenlive — Video Editing Without Premiere Pro

Kdenlive is an open-source, non-linear video editor that can replace many everyday functions of Premiere Pro.

You can arrange video clips on a timeline, cut and trim footage, add transitions, work with multiple audio and video tracks, apply effects, and export projects in different formats.

It is suitable for YouTube videos, educational projects, documentaries, social-media content, and general video editing.

Professional editors working on extremely complex productions may still prefer commercial software, but Kdenlive provides a strong free starting point.

Best replacement: Adobe Premiere Pro

5. Blender — A Powerful After Effects and 3D Alternative

Blender is perhaps the most powerful tool on this list.

It is best known as a 3D creation suite, but its capabilities go far beyond modeling. Blender includes animation, rendering, compositing, simulation, video editing, and visual-effects tools.

Its compositor and animation system can be used for motion graphics and visual-effects workflows.

Blender isn't a direct one-to-one replacement for every After Effects feature, but it can handle many tasks involving animation, 3D graphics, compositing, and visual effects.

Best replacement: After Effects for many VFX and motion-graphics workflows

6. Scribus — Desktop Publishing Without InDesign

Scribus is an open-source desktop publishing application.

It is designed for creating documents that require precise page layouts, including brochures, newsletters, posters, magazines, books, and other print materials.

Scribus supports professional publishing features such as color management, master pages, typography, and PDF creation.

If you mainly use InDesign to produce structured documents and print layouts, Scribus is worth trying.

Best replacement: Adobe InDesign

7. Audacity — Audio Editing Without Audition

For audio editing, Audacity remains one of the most accessible open-source choices.

It allows users to record audio, cut and rearrange tracks, remove unwanted sections, apply effects, adjust volume, and work with multiple audio tracks.

Podcasters, students, musicians, YouTubers, and voice-over creators can use it for many everyday audio tasks.

Audacity doesn't attempt to replicate every advanced feature of Adobe Audition, but it covers the fundamentals extremely well.

Best replacement: Adobe Audition

8. darktable — An Alternative to Lightroom

Photographers looking for an open-source Lightroom alternative should consider darktable.

darktable is designed around RAW photography and non-destructive image editing. It also provides tools for organizing and processing large collections of photographs.

You can adjust exposure, colors, contrast, sharpness, white balance, and other image properties while maintaining a non-destructive workflow.

For photographers who don't want to pay for Lightroom, darktable can provide a capable foundation for managing and processing images.

Best replacement: Adobe Lightroom

9. PDF Arranger — A Simple Acrobat Alternative

Adobe Acrobat is used for much more than simply reading PDFs. However, many people primarily need basic PDF manipulation.

PDF Arranger provides a simple open-source solution for organizing PDF pages.

You can merge documents, split files, reorder pages, rotate pages, and create new PDFs from existing pages.

It doesn't replace every advanced Acrobat feature, particularly sophisticated form, signing, and enterprise functions. But for basic PDF management, it can be a lightweight alternative.

Best replacement: Adobe Acrobat for basic PDF organization

Can These Tools Really Replace Adobe?

The answer depends on what you do.

A professional design studio with an established Adobe workflow may not be able to replace Creative Cloud overnight. Adobe applications have extensive integrations, standardized workflows, commercial support, and highly specialized features.

For an individual creator, however, the situation is different.

A practical open-source creative setup could look like this:

Adobe Software Open-Source Alternative
Photoshop GIMP
Illustrator Inkscape
Photoshop/Digital Painting Krita
Premiere Pro Kdenlive
After Effects Blender
InDesign Scribus
Audition Audacity
Lightroom darktable
Acrobat PDF Arranger

The biggest advantage is that these applications can be used independently. You don't have to replace everything at once.

For example, a YouTube creator could start with GIMP + Kdenlive + Audacity. A photographer might prefer darktable + GIMP. A graphic designer could begin with Inkscape + Krita.

Why Open Source Is Worth Considering

Open-source software offers several important advantages. You generally avoid recurring subscription fees, can inspect or modify the source code, and can often install the applications on supported systems without being locked into a particular ecosystem.

Another major benefit is community development. Many open-source projects are continuously improved by contributors around the world.

There is also less pressure to learn an entire software ecosystem simply because you are paying for it.

Final Thoughts

You don't need to abandon Adobe immediately to explore open-source software. Start with the application that matches your most common task.

GIMP is an excellent starting point for image editing, Inkscape for vector graphics, Kdenlive for video, Audacity for audio, and darktable for photography. For more advanced creative work, Blender and Krita can take you considerably further.

Together, these nine applications demonstrate how far open-source creative software has come. They may not reproduce every Adobe feature perfectly, but for many students, creators, freelancers, educators, and hobbyists, they can provide a powerful Adobe-free creative workflow without a monthly Creative Cloud subscription.

Friday, September 4, 2026

How to Build an AI Agent: A Simple Guide for Anyone

 

How to Build an AI Agent: A Simple Guide for Anyone

https://technologiesinternetz.blogspot.com


Artificial intelligence has moved beyond simple chatbots. Today, AI systems can understand instructions, use tools, retrieve information, make decisions, and complete multi-step tasks. These systems are commonly called AI agents.

The good news is that you do not need to be an AI researcher to understand how an agent works. With basic programming knowledge and Python, you can build a simple AI agent and gradually add more sophisticated capabilities.

This guide explains the basic architecture of an AI agent and shows how to create a simple one using Python.

What Is an AI Agent?

An AI agent is a software system that can receive a goal, decide what actions are necessary, use available tools, and produce a result.

A traditional chatbot might simply follow this pattern:

User → Question → AI → Answer

An AI agent can follow a more flexible process:

Goal → Understand → Plan → Use Tools → Observe Results → Decide → Respond

For example, imagine asking an agent:

"Find the weather in Kolkata and tell me whether I should carry an umbrella."

The agent could determine that it needs weather information, call a weather service, analyze the result, and provide a recommendation.

The important difference is that an agent can take actions, rather than simply generating text.

The Main Components of an AI Agent

A simple agent generally has five major components.

1. Model

The AI model provides the reasoning and language capabilities.

This could be a cloud-based large language model or a locally running model.

The model interprets instructions and helps determine what should happen next.

2. Instructions

The agent needs clear instructions describing its role and behavior.

For example:

You are a helpful research assistant.
Answer questions clearly.
Use available tools when necessary.
Do not invent information.

These instructions provide the agent with its basic behavior.

3. Tools

Tools allow an agent to interact with the outside world.

Examples include:

  • Web search
  • Calculator
  • Weather API
  • Database
  • File system
  • Calendar
  • Email service
  • Python programs

Without tools, an AI model is largely limited to the information and capabilities available within its model context.

4. Memory

Memory allows an agent to retain useful information.

There are different types of memory. Short-term memory can contain the current conversation, while longer-term memory can store information that should be retrieved later.

For a beginner project, you can start with simple conversation history rather than building a complicated memory system.

5. Agent Loop

The agent loop controls the interaction between the model and its tools.

A simplified version looks like:

User Request
     ↓
AI Model
     ↓
Does it need a tool?
   ↙       ↘
 Yes        No
 ↓           ↓
Tool       Answer
 ↓
Result
 ↓
AI Model
 ↓
Final Answer

This loop is one of the most important ideas behind tool-using AI agents.

Building a Simple AI Agent with Python

Let's create a small educational agent.

Our agent will be able to perform simple calculations.

The goal is not to build a production AI assistant but to understand the basic architecture.

Step 1: Create the Tools

First, create a calculator function.

def calculator(a, b, operation):

    if operation == "add":
        return a + b

    if operation == "subtract":
        return a - b

    if operation == "multiply":
        return a * b

    if operation == "divide":
        if b == 0:
            return "Cannot divide by zero."
        return a / b

    return "Unknown operation."

This function becomes one of the agent's tools.

The AI model can determine when the calculator is useful.

Step 2: Create an Agent Function

Now we can create a simple agent structure.

def agent(user_input):

    print("Agent received:", user_input)

    # In a real agent, an AI model would
    # decide which tool to use.

    if "calculate" in user_input.lower():
        result = calculator(10, 5, "multiply")
        return f"The result is {result}"

    return "I don't have a tool for this request."

We can test it:

print(agent("Calculate something"))

The example is deliberately simple. A real AI agent would use an AI model to interpret the user's request instead of relying on a basic keyword check.

Connecting an AI Model

The next step is connecting your Python application to an AI model.

A typical architecture looks like this:

Python Application
       ↓
    AI Model
       ↓
 Tool Decision
       ↓
   Python Tool
       ↓
 Tool Result
       ↓
    AI Model
       ↓
 Final Response

Modern AI APIs and frameworks can support structured tool or function calling. This allows a model to return information indicating which tool should be called and what arguments it needs.

For example, the model might conceptually produce:

{
    "tool": "calculator",
    "arguments": {
        "a": 20,
        "b": 5,
        "operation": "divide"
    }
}

Your Python program can then execute the corresponding function and send the result back to the model.

Step 3: Add Multiple Tools

Once the basic system works, you can add more tools.

For example:

def get_weather(city):
    # Connect to a weather API
    pass


def search_database(query):
    # Search your database
    pass


def calculator(a, b, operation):
    # Perform calculation
    pass

The agent now has several possible actions.

The model can decide which tool is appropriate for a particular request.

For example:

"What is 25 × 40?"

→ Calculator

"What is the weather today?"

→ Weather tool

"Find customer order 105."

→ Database tool

This is where an application begins to behave more like an agent.

Step 4: Give the Agent Memory

An agent becomes more useful when it can maintain context.

A simple implementation can store previous messages:

conversation = []

conversation.append({
    "role": "user",
    "content": "My name is Rahul."
})

conversation.append({
    "role": "assistant",
    "content": "Nice to meet you, Rahul."
})

The conversation history can then be supplied to the model when generating the next response.

For more advanced applications, you might store information in a database or vector store and retrieve only relevant memories.

Step 5: Add an Agent Loop

A more realistic agent repeatedly evaluates what it should do.

Conceptually:

while not finished:

    response = ask_model()

    if response_requires_tool(response):
        result = execute_tool(response)
        add_result_to_context(result)

    else:
        finished = True

This creates the basic reason → act → observe cycle.

The model reasons about the task, the application performs an action, and the result is returned to the model.

The process continues until the agent can provide a final answer.

Safety and Error Handling

A useful agent also needs boundaries.

Never assume that a model will always make the correct decision.

Your application should validate tool arguments before executing them.

For example, if an agent has access to a financial tool, you should not allow it to execute arbitrary transactions simply because the model requested one.

Good agent design includes:

  • Input validation
  • Authentication
  • Permission controls
  • Tool restrictions
  • Error handling
  • Timeouts
  • Logging
  • Rate limits
  • Human approval for sensitive actions

The more powerful the tools, the more important these protections become.

Should You Build an Agent From Scratch?

Building an agent from scratch is an excellent way to understand how the technology works.

However, you don't always need to write everything yourself.

Python developers can use AI frameworks and libraries that provide features such as:

  • Tool calling
  • Memory management
  • Workflow orchestration
  • Agent loops
  • Structured outputs
  • Retrieval
  • Evaluation

Frameworks can speed up development, but understanding the underlying concepts is still important. Otherwise, debugging an agent can become difficult.

Ideas for Your First AI Agent

If you're new to agent development, start with a small project.

You could build:

AI Calculator Agent
An agent that decides when to use mathematical functions.

Research Assistant
An agent that searches approved information sources and summarizes results.

File Assistant
An agent that reads documents and answers questions about them.

Personal Productivity Agent
An agent that organizes tasks and reminders.

Coding Assistant
An agent that analyzes code, explains errors, and suggests improvements.

Start with one or two tools. Once the system works reliably, add more capabilities.

Final Thoughts

Building an AI agent may sound complicated, but the fundamental idea is surprisingly straightforward.

An agent combines an AI model, instructions, tools, memory, and a control loop. The model decides what should happen, your application executes permitted actions, and the results are returned to the model for the next step.

The best way to learn is to build something small. Start with a calculator or simple information-retrieval agent, understand the tool-calling process, and then gradually introduce memory, multiple tools, asynchronous execution, and more advanced workflows.

You don't need to build the next superintelligent system to learn AI agents. A small working agent is enough to teach you the architecture, challenges, and possibilities of agentic AI.

Tuesday, September 1, 2026

7 Async Patterns for Running AI Agents in Python

 

7 Async Patterns for Running AI Agents in Python

https://technologiesinternetz.blogspot.com


AI agents are becoming more capable, but making an agent intelligent is only part of the challenge. A practical agent also needs to perform tasks efficiently: calling APIs, reading files, searching databases, waiting for external services, and sometimes managing several operations at the same time.

This is where asynchronous programming in Python becomes useful.

Python's asyncio framework allows an application to perform other work while it is waiting for an operation to finish. For AI agents, this can significantly improve responsiveness, particularly when the workload is dominated by network requests and other I/O operations.

In this article, we will explore seven useful async patterns for running agents in Python, with simple examples and explanations of when each pattern makes sense.

What Is Async Programming?

In traditional synchronous code, operations generally execute one after another.

Imagine an agent needs to:

  1. Search the web.
  2. Call a weather API.
  3. Query a database.
  4. Ask an LLM for a response.

If every operation waits for completion before the next one starts, the agent can spend a lot of time simply waiting.

Asynchronous programming changes this behavior.

An asynchronous function can pause while waiting for an I/O operation, allowing other tasks to run during that time.

A basic Python async function looks like this:

import asyncio

async def agent_task():
    print("Agent is working...")
    await asyncio.sleep(1)
    print("Task completed")

asyncio.run(agent_task())

The await keyword tells Python that the function can pause at that point while other asynchronous work gets an opportunity to execute.

1. Sequential Async Pattern

The first pattern is the simplest: use asynchronous functions but execute operations sequentially.

async def run_agent():
    result1 = await call_tool_one()
    result2 = await call_tool_two()

    return result1, result2

Although the functions are asynchronous, the second operation does not begin until the first one finishes.

This approach is useful when tasks depend on each other.

For example:

Search → Analyze Results → Generate Answer

The agent cannot analyze the results until the search has completed.

When to use it

Use sequential async execution when:

  • One operation depends on another.
  • Execution order matters.
  • You want simple and predictable control flow.

Async does not automatically mean parallel execution. Sometimes sequential execution is exactly what an agent needs.

2. Concurrent Tasks with asyncio.gather()

When tasks are independent, running them concurrently can save time.

Python provides asyncio.gather() for this purpose.

async def run_agent():
    results = await asyncio.gather(
        search_web(),
        get_weather(),
        query_database()
    )

    return results

Instead of waiting for each operation separately, the agent starts all three asynchronous operations and waits for their results.

This is particularly useful when an agent needs information from several independent tools.

For example:

Web Search + Database Query + API Request

If each operation takes two seconds, sequential execution could take roughly six seconds. Concurrent execution can potentially reduce the waiting time considerably, assuming the services can actually run concurrently.

3. Creating Background Tasks

Sometimes an agent needs to start work without immediately waiting for the result.

Python's asyncio.create_task() allows you to schedule a coroutine as a task.

async def agent():
    background_task = asyncio.create_task(
        update_memory()
    )

    result = await perform_main_task()

    await background_task

    return result

Here, update_memory() can run while the main task is being processed.

This pattern can be useful for agent activities such as:

  • Updating non-critical state
  • Preparing data
  • Logging
  • Prefetching information
  • Performing background maintenance

However, background tasks should not simply be forgotten. If the result matters, you should eventually await the task or otherwise manage its lifecycle.

4. Producer-Consumer Pattern with asyncio.Queue

More advanced agents sometimes need a pipeline where one part produces work and another part processes it.

An asyncio.Queue is useful for this architecture.

import asyncio

queue = asyncio.Queue()

async def producer():
    for item in range(5):
        await queue.put(item)

async def consumer():
    while True:
        item = await queue.get()

        if item is None:
            break

        print("Processing:", item)
        queue.task_done()

The producer puts jobs into the queue, while the consumer retrieves and processes them.

This pattern works well for agents that handle many jobs, such as:

Incoming Requests → Task Queue → Agent Workers

You can also create multiple consumers to process tasks concurrently.

5. Async Timeouts

Agents often depend on external services. An API may become slow, unavailable, or temporarily unresponsive.

Allowing an agent to wait indefinitely is usually a bad idea.

Python provides timeout mechanisms that can prevent this problem.

For example:

async def run_agent():
    try:
        result = await asyncio.wait_for(
            call_external_tool(),
            timeout=10
        )

        return result

    except asyncio.TimeoutError:
        return "The tool timed out."

If the operation takes longer than ten seconds, the agent can stop waiting and take another action.

Timeouts are especially useful for:

  • API calls
  • Database operations
  • Web requests
  • Agent tool calls
  • External model services

A robust agent should have a strategy for handling slow dependencies.

6. Retry with Exponential Backoff

External services can fail temporarily.

For example, an API might return an error because of a temporary network problem or rate limit.

Instead of immediately giving up, an agent can retry the operation.

A simplified pattern looks like this:

async def retry_operation():
    delay = 1

    for attempt in range(3):
        try:
            return await call_tool()

        except Exception:
            if attempt == 2:
                raise

            await asyncio.sleep(delay)
            delay *= 2

The delays are approximately:

1 second → 2 seconds → 4 seconds

This technique is called exponential backoff.

It prevents an agent from repeatedly hitting a failing service in rapid succession.

In production applications, retries should normally distinguish between temporary errors and permanent failures. Not every exception should automatically trigger another request.

7. Async Agent Pipelines

The final pattern combines several async techniques into a structured workflow.

Imagine an agent that performs:

Input → Planning → Tool Calls → Validation → Final Response

Each stage can be represented as an asynchronous function.

async def run_agent(user_input):

    plan = await create_plan(user_input)

    results = await asyncio.gather(
        execute_tool(plan[0]),
        execute_tool(plan[1])
    )

    validated = await validate_results(results)

    response = await generate_response(validated)

    return response

This approach provides a clean architecture for larger agents.

Independent tool calls can execute concurrently, while dependent stages remain sequential.

For example:

User Request
     ↓
   Planner
     ↓
 ┌───┴────┐
 ↓        ↓
Tool A   Tool B
 └───┬────┘
     ↓
 Validator
     ↓
 LLM Response

This hybrid model is often more practical than trying to make everything concurrent.

Choosing the Right Pattern

Different agent workloads require different approaches.

Pattern Best Use
Sequential async Dependent operations
asyncio.gather() Independent tasks
Background tasks Non-blocking supporting work
Async queue Job pipelines and worker systems
Timeouts Unreliable or slow services
Retry/backoff Temporary failures
Async pipeline Multi-stage agent workflows

The important point is that concurrency should be intentional.

Running everything simultaneously can create problems such as API rate-limit violations, excessive memory usage, race conditions, and difficult-to-debug failures.

Async Doesn't Make CPU-Heavy Work Automatically Faster

One common misconception is that asyncio makes every Python program faster.

It does not.

Async programming is particularly effective for I/O-bound workloads, where the application spends significant time waiting for external operations.

Examples include:

  • HTTP requests
  • Database queries
  • File operations
  • Network services
  • Remote AI model calls

CPU-intensive operations may require other approaches, such as multiprocessing or specialized libraries.

Best Practices for Async Agents

When building production-quality agents, keep several principles in mind.

Use concurrency selectively. Only run tasks concurrently when they are independent.

Set timeouts. External operations should not be allowed to block an agent indefinitely.

Handle exceptions. One failed tool call should not necessarily crash the entire agent.

Limit concurrency. If an agent makes hundreds of requests simultaneously, the target service or your own application may become overloaded.

Track tasks carefully. Background tasks should have clear ownership and lifecycle management.

Keep workflows understandable. Highly complicated async code can become harder to maintain than simple sequential code.

Conclusion

Asynchronous programming is an important skill for building responsive Python agents. The asyncio ecosystem provides several patterns that can help agents manage multiple operations efficiently.

The seven patterns discussed here—sequential async execution, concurrent tasks, background tasks, producer-consumer queues, timeouts, retry with exponential backoff, and async pipelines—cover many common agent architectures.

The best design is rarely the one that uses the most concurrency. Instead, a good agent uses async execution where it provides a real advantage while keeping dependencies, failures, and task lifecycles under control.

Once you understand these patterns, you can begin building Python agents that interact with multiple tools, APIs, databases, and AI models without becoming unnecessarily slow or difficult to manage.

Organize Your Files Automatically with Python

  Organize Your Files Automatically with Python A messy downloads folder can become surprisingly difficult to manage. Images, PDFs, documen...