Skip to main content

Build your first extension

Extensions are modular components that add specific capabilities to your agent. They can process inputs, generate outputs, or connect to external services, making your agent more powerful and versatile. While TEN Agent includes many pre-built extensions for common use cases, you may need to develop your own to add custom functionality, integrate with proprietary services, or optimize for specific requirements.

This guide walks you through creating your first TEN Agent extension. You'll build a "Hello World" extension in your choice of Python, Go, or C++.

Prerequisites

Before starting:

  • Complete the Agent quickstart
  • Ensure Docker Compose is running
  • Understand basic container operations

Implementation

Follow these steps to create your first extension.

Start the development environment

Run the following command on your local machine:


_2
# Run on your local machine
_2
docker compose up

You see output similar to the following:


_10
Attaching to ten_agent_dev, ten_agent_playground
_10
ten_agent_dev | cd agents && tman designer
_10
ten_agent_dev | :-) Starting server at http://0.0.0.0:49483
_10
ten_agent_playground | ▲ Next.js 14.2.4
_10
ten_agent_playground | - Local: http://localhost:3000
_10
ten_agent_playground | - Network: http://0.0.0.0:3000
_10
ten_agent_playground |
_10
ten_agent_playground | ✓ Starting...
_10
ten_agent_playground | ✓ Ready in 429ms
_10
...

You now have:

  • Development server ten_agent_dev at http://0.0.0.0:49483
  • Playground interface ten_agent_playground at http://localhost:3000

Create the extension

  1. Enter the development container:


    _2
    # Run on your local machine
    _2
    docker exec -it ten_agent_dev bash

  2. Navigate to the extensions directory:


    _2
    # Run inside Docker container
    _2
    cd /app/agents/ten_packages/extension

  3. Create your extension using the appropriate template:

    cd /app/agents/ten_packages/extension
    tman create extension hello_world --template=default_async_extension_python@0.6 --template-data class_name_prefix=HelloWorld

    The log shows confirmation that the package was created successfully.


    _1
    Package 'extension:hello_world' created successfully in '/app' in 3 seconds.

Define the extension API

Open manifest.json in the hello_world directory and add data_in and cmd_out API definitions to the file:


_43
{
_43
"type": "extension",
_43
"name": "hello_world",
_43
"version": "0.3.1",
_43
"dependencies": [
_43
{
_43
"type": "system",
_43
"name": "ten_runtime_python",
_43
"version": "0.3.1"
_43
}
_43
],
_43
"package": {
_43
"include": [
_43
"manifest.json",
_43
"property.json",
_43
"BUILD.gn",
_43
"**.tent",
_43
"**.py",
_43
"README.md",
_43
"tests/**"
_43
]
_43
},
_43
"api": {
_43
"data_in": [
_43
{
_43
"name": "text_data",
_43
"property": {
_43
"text": {
_43
"type": "string"
_43
},
_43
"is_final": {
_43
"type": "bool"
_43
}
_43
}
_43
}
_43
],
_43
"cmd_out": [
_43
{
_43
"name": "flush"
_43
}
_43
]
_43
}
_43
}

Build and deploy

  1. Return to the project root:


    _2
    # Run inside Docker container
    _2
    cd /app

  2. Build the extension:


    _2
    # Run inside Docker container
    _2
    task use

  3. Apply changes:

    • First build: No restart needed
    • Subsequent updates: Refresh the playground page. If changes do not appear, restart the server container.

    Restart the server for ten_agent_dev

Congratulations! You’ve successfully created your first extension.