/routines in Telegram.
What a routine needs
Telegram-only hooks (
handle_callback, handle_message, MESSAGE_STATES, cleanup) are listed in the overview.
1. Choose the folder
All paths are relative to the folder you installed Condor into. Create the folder if it doesn’t exist. File names must be valid Python module names, such as
momentum_scanner.py. Files that start with _ are skipped in agent and shared folders.
2. Write the routine
This routine measures momentum and volume on recent candles for a few pairs. It returns aRoutineResult, so the Workspace shows a table and Telegram shows the one-line summary.
get_candlestakesmax_records, notlimit. The server returns a list of candles, each withtimestamp,open,high,low,close,volumeandquote_asset_volume.get_pricesreturns{"connector": ..., "prices": {"BTC-USDT": 81714.0, ...}, "timestamp": ...}. Read the prices fromresult["prices"].
3. Test it
Condor picks up the file without a restart. Then run it from any of these:- Workspace: open Routines, select
momentum scanner, open Config to change settings, and click Run. Switch to Output to see the table. - Telegram:
/routines→ ⚡ Momentum Scanner → ▶️ Run. Sendkey=valuelines, such aslookback=48, to change the config first. Telegram lists only the general and shared routines, so a routine in an agent’s folder doesn’t appear there. - Chat: ask Condor “run momentum_scanner with interval=1h”.
Failed to load routine or Failed to load agent routine. In Telegram, 🔄 Reload retries files that failed before.
4. Use it from an agent
If the routine is in the agent’s ownroutines/ folder or in _shared/routines/, the agent can run it. When the agent runs a loop, its prompt lists the routine and tells it to call:
loop.md so the agent knows when to use it:
run waits up to 120 seconds. A longer run keeps going in the background, and the agent reads the result later with action="get_instance". A Dry Run refuses routine runs, so test the routine on its own first.
See MCP Tools for the agent tool list and Architecture for how loops work.
A routine that agents run has no Telegram chat behind it. Don’t rely on
context.bot.send_message to deliver results. Return a RoutineResult or save a report instead.Continuous routines
A continuous routine setsCONTINUOUS = True and loops until you stop it. Condor stops it by cancelling the task, so catch asyncio.CancelledError and return a summary.
This one checks a price every few seconds and rewrites a single live report each time:
Let Condor write it
You can describe the routine in the chat instead:manage_routines(action="create_routine"), checks that it loads, and runs it to test it. It saves to .condor/agents/condor/routines/ unless you ask for a shared routine, which goes to .condor/agents/_shared/routines/. An agent asked to write a routine saves it to its own routines/ folder.
Best practices
Keep routines deterministic
Keep routines deterministic
The same config and the same market data should give the same result. Put judgment in the agent’s skills and loop instructions, not in the routine.
Return errors as results
Return errors as results
Return a short message such as
"No server available" when something expected is missing. An exception marks the run as failed and the Workspace shows the error.Describe every field
Describe every field
The
Config docstring and each Field(description=...) are what you, Condor and agents read to decide how to run the routine.Keep routines read-only unless you mean it
Keep routines read-only unless you mean it
A routine runs with the full API client. Nothing stops it from placing orders or deploying bots, so keep trading actions in the agent, where the risk engine checks them.
Handle cancellation in continuous routines
Handle cancellation in continuous routines
Catch
asyncio.CancelledError around the loop and return a summary.
