Templates
Code Capsules provides a variety of agent template repos for you to use as the base for your Agent Capsule.
Each template comes with a tutorial on how to successfully deploy the template, and can be accessed from our GitHub pages. See the list of available templates below:
Base Agent
Basic agent communication
RAG (context) functionality
Telegram Bot Agent
Base Agent functionality (forked off Base Agent)
Runs a Telegram bot which calls the agent for communication
Google Calendar Agent
Base Agent functionality (forked off Base Agent)
Add events to Google Calendar
Get a list of events from Google Calendar
Architecture
Each template consists of the same base architecture, containing the following:
A list of endpoints: required for interaction with the Code Capsules Agent Chat tab
A memory store: allows for the agent to retain overall memory. Useful when the agent needs to store some memory "globally" (i.e. will be applied across all prompts). By default, a connection attempt will be made to a Redis instance, but will fall back to an in-memory store if unavailable
A vector store: allows for the agent to gain context through RAG. Using the prescribed endpoints, one can add context using text or a URL. By default, a connection attempt will be made to a Redis instance, but will fall back to an in-memory vector store if unavailable
Creating a New Agent
Follow the following procedure to begin creating your new agent. In this example, we will use Google as the provider, but there are other options available.
If you already have a free or paid tier Google AI Studio account and API key, you can move to step 3, else continue to step 2.
Follow the following guidelines to create a new Google Gemini API key: https://ai.google.dev/gemini-api/docs/api-key. Make sure to copy your key somewhere safe as it will be needed later.
Navigate to one of the template repositories on GitHub as described above. If you are new to AI Agent development, it is recommended to start with a simple Base Agent.
Using the template repo, create your own new repository by following the steps here: https://docs.github.com/en/repositories/creating-and-managing-repositories/creating-a-repository-from-a-template#creating-a-repository-from-a-template.
Follow the setup steps for the template in the relevant README.md file which can be found in the same GitHub repository.
Create a new Agent Capsule, linking your newly created repo, and adding your provider, model, and API key when requested.
Once the capsule is built, navigate to the Chat page - ask your newly deployed Agent Capsule anything you'd like! Remember: if you are using a template, the agent will most likely be confined to a specific purpose, so be sure to read the README.md file for more information on its capabilities.
You can now modify your codebase however you'd like to include new tools, context, and more.
Agent Capsule templates have been built with the capabilities of using either a Redis or in-memory vector store. When using the in-memory option (i.e. no Redis Capsule is linked), it is recommended to scale the Agent Capsule to the following in order to ensure optimal performance:
CPU 25%
Memory 1GB
Replicas 1
To do this, visit the Agent Capsule Scale page.
Setting up a Vector Store (RAG)
Each template has been written to use memory as a vector store for RAG. However, the templates also cater for connections to a Redis instance as its vector store. In order to set this up, follow the following steps:
Create a Redis Capsule.
Copy the Connection String in the Details tab of your Redis Capsule.
Navigate to the Config page of your Agent Capsule.
On the Environment Variables section (on the right-hand side), click the Text Editor.
Add the following at the bottom of the Environment Variables list:
Wait for the Agent Capsule to restart - it should now use the Redis Capsule as its vector store.
Testing RAG
In order to test RAG functionality, do the following:
Make a call to the following endpoint:
Navigate to the Agent Capsule Chat tab.
Ask the agent the following question:
The agent should respond with something along the lines of:
Accessing documentation
All agent templates come with pre-written OpenAPI documentation. In order to access this documentation, an environment variable needs to be added to the Agent Capsule. Follow the following steps to do so:
Open Code Capsules.
Navigate to the Config page of your Agent Capsule.
On the right-hand side, in the Environment Variables section, click 'Text Editor'.
Paste the following into the bottom of the editor:
Click 'Save'.
Wait for the Agent Capsule to restart.
Navigate to the 'Details' page of your Agent Capsule.
Copy the 'Public URL' link.
In a new browser tab, paste the URL and append
/api-docsto the end of the URL.Once the page is loaded, you should see some fully functional OpenAPI documentation for your agent, unique to your selected agent template.
These documents are served directly from the src/docs/swagger.json file in the agent repo.
Customisation
If you've followed the above steps to create an Agent Capsule, you're probably now looking into how you can add your own tools, context, and other customisation. Follow the topics below to investigate how to do this.
Changing the Provider and Model
Changing the public AI provider and model through the Code Capsules site is easy. You can do this by navigating to the Config page for the Agent Capsule. Here, you can edit the Agent Config to change these details to cater your needs. After the changes are applied, the Agent Capsule will restart and use your newly provided configuration. See more here.
Changing the System Prompt
Each agent template comes with a pre-written system prompt found in the src/modules/agent/config/system-prompt.ts file. This will provide your agent with a base prompt from which it will build it's context.
It is important to note that changing this prompt will require you to push your changes to the relevant GitHub repo and branch, and ensuring that a new build is started in Code Capsules. Once the build is complete, your changes will be ready for use.
Adding New Tools
Adding a new tool to your agent has been made easy with the simple layout structure built into the agent templates. Follow these simple steps to add a new tool, with a side-by-side example of creating a new getWeather tool.
Navigate to the /src/modules/agent/tools/implementations folder.
Create a new file to describe your new tool.
New file:
src/modules/agent/tools/implementations/my-new-tool.tool.ts
New file:
src/modules/agent/tools/implementations/get-weather.tool.ts
In your new file, add code with the following structure, replacing where necessary:
In the
src/modules/agent/tools/implementations/index.tsfile, export your new tool.
In the
src/modules/agent/tools/tools-manager.tsfile, add your new tool to the list in the constructor.
(Optional) Add new System Prompt context in the
src/modules/agent/config/system-prompt.tsfile.
Push your code.
Code Capsules, if configured to do so, will automatically rebuild your Agent Capsule. Once complete, navigate to your Chat page and ask the agent a question.
Last updated
Was this helpful?