Agent Creation
Agents are the core unit of YorN. Each agent encapsulates a trading strategy, risk parameters, and execution logic. This guide covers everything from creating agents with natural language to writing custom Strategy classes.
What is an Agent
A YorN agent is an autonomous program that monitors prediction markets, evaluates trading opportunities, and executes trades based on a defined strategy. Every agent consists of three components:
- Strategy -- The decision-making logic that generates buy/sell signals
- Risk Manager -- Constraints on position size, daily loss limits, and exposure
- Executor -- The engine that submits orders to Kalshi (paper or live)
Agents run continuously, processing market data in real time via WebSocket feeds. When the strategy generates a signal with sufficient confidence, the executor places the trade after the risk manager approves it.
Prompt
Describe thesis
Generate
AI writes code
Validate
AST safety check
Deploy
Start trading
Learn
Self-improve
Creating via Natural Language
The simplest way to create an agent is to describe your trading thesis in plain English. The AI agent builder uses Claude to parse your intent, identify market categories, define entry/exit conditions, and generate a complete Strategy class.
Writing Effective Prompts
A good prompt specifies four things: what market to trade, when to enter, when to exit, and how much to risk. Here are examples ranked from basic to advanced:
The more specific your prompt, the better the generated strategy. Include price thresholds, position sizing rules, and exit conditions for the best results.
The Strategy Class
Every agent is powered by a Strategy class. Whether created by AI or written manually, all strategies follow the same structure. The Strategy base class provides lifecycle hooks that you override with your logic.
Signal Object
The Signal object is the return type of the evaluate method. It tells the executor what to do:
Market Data Object
The market_data dictionary passed to evaluate contains:
AST Safety Validation
Every generated or uploaded strategy undergoes Abstract Syntax Tree (AST) validation before deployment. This ensures that agent code cannot perform dangerous operations.
Blocked Operations
-
importstatements -- No external library imports allowed -
File I/O -- No
open(),read(),write()calls -
Network access -- No
requests,urllib,socketusage -
System calls -- No
os.system(),subprocess,eval(),exec() - Global state mutation -- No modifying module-level variables
Allowed Operations
- Arithmetic and comparison operators
-
Built-in math functions:
min,max,abs,round,sum - List, dict, and string operations
-
Control flow:
if,for,while,try/except -
Instance variable access on
self
If AST validation fails, the agent will not be created. The error response includes the specific violation so you can adjust your prompt or code.
Deploying Agents
Once an agent passes validation, it can be deployed in paper or live mode. Deployment creates a persistent process that monitors markets and executes the strategy.
Configuration Options
Managing Agents
The dashboard provides full control over your deployed agents. You can pause, resume, stop, or reconfigure agents at any time.
Running
Agent is actively monitoring markets and executing trades.
Paused
Agent is paused. Existing positions remain open but no new trades are placed.
Stopped
Agent is fully stopped. All positions are closed or marked for manual review.
Agent API Endpoints
Next Steps
- Strategies -- Create custom AI-generated strategies and explore the signal lifecycle
- Coordination Modes -- Run multiple agents as a coordinated team
- API Reference -- Full endpoint documentation