Implement custom logic
Overview
After creating a Warden Agent, you can update it, implementing custom logic.
There are two ways to do it:
- Update the Agent through the CLI, using an AI assistant
- Directly edit the Agent's code
To learn more, see the sections below.
Build with AI
You can edit your Agent through the CLI, in the AI-powered build mode.
For a list of commands available in this mode, see Build mode.
To start building with AI, take these steps:
-
If your Agent is running, stop it with CTRL+C. Navigate to your project's root directory and initiate Warden Code:
warden -
Then enter the build mode:
/build -
On the first run, you'll be prompted to select an LLM provider (OpenAI or Anthropic) and set a model and the API key.
tipYou can configure multiple providers. The configuration file is located in the user home directory at
.warden/config.jsonand shared across all projects. -
If needed, add another provider or switch between providers and models:
/modelSwitching models within the same provider preserves your conversation history. To go back during selection, press ESC.
-
Prompt the assistant to update the main Agent code or any file in the project. Responses stream token-by-token with real-time display.
tipIf you update your Agent's skills, reflect it in the Agent Card.
-
After the AI applies code changes, the project is automatically rebuilt.
You can also manually rebuild your Agent:
/rebuildnoteCode changes trigger
npm run build. Ifpackage.jsonwas modified,npm installruns first. If the build fails, the error output is fed back to the AI for automatic correction (up to 2 retries). -
In a separate terminal window, navigate to your project and run the Agent:
npm start -
To verify the update, return to the window where Warden Code is running and chat with the Agent:
/chatThe Agent URL is resolved automatically from the
AGENT_URLin your.envfile. By default, it's set tohttp://localhost:3000. If needed, you can pass the URL explicitly:/chat http://localhost:3000 -
To exit the chat and the build modes, use this:
/exit
Edit the code
You can directly edit your Agent's code in src/agent.ts.
To implement custom logic, use the functions exposed by Warden Code.
Next steps
Now you can do the following: