📢 Beta: Uses DAL service and agent APIs. Test before production.
Learn to build an AI trading agent in DAL using
services, agents, and the
ai:: namespace.
Time: 45 minutes
Difficulty: Intermediate
Prerequisites: Basic DAL (services, fn,
literals)
📝 Note: DAL uses
ai::create_agent(config)andai::create_agent_coordinator()for agents. Config is a literal{ role: "...", capabilities: [...] }. See Syntax Reference and API Reference.
An AI-powered trading agent that:
ai::create_agent(config)if (condition) and
log::info (parser-accurate)mkdir ai-trading-agent && cd ai-trading-agent
touch TradingAgent.dalUse @trust and
@chain with a service.
Store agent id and config in fields (maps/literals).
// TradingAgent.dal
@trust("hybrid")
@chain("ethereum")
service AITradingAgent {
agent_id: string = "";
total_trades: int = 0;
successful_trades: int = 0;
fn create_agent(name: string, strategy: string, budget: int, risk_level: int) {
let config = {
role: "trader",
capabilities: ["analysis", "reasoning"]
};
let agent_instance = ai::create_agent(config);
self.agent_id = agent_instance;
log::info("agent", "AI Trading Agent created");
}
fn get_agent_id() -> string {
return self.agent_id;
}
}
Use ai:: functions as in the API Reference. Pass
literals for options.
fn analyze_sentiment(asset: string) -> string {
let market_data = { asset: asset };
let sentiment = ai::analyze_text("sentiment for " + asset);
return sentiment;
}
fn predict_price(asset: string, timeframe: int) -> int {
let data = {
asset: asset,
timeframe_hours: timeframe
};
let prediction = ai::generate_text("price prediction");
return 1000;
}
Use if (condition) with parentheses.
Use log::info("tag", message) (two
arguments).
fn make_trade_decision() -> string {
if (self.agent_id == "") {
log::info("agent", "Create agent first");
return "error";
}
let sentiment = self.analyze_sentiment("ETH");
if (sentiment == "bullish") {
log::info("agent", "Decision: BUY");
return "buy";
} else if (sentiment == "bearish") {
log::info("agent", "Decision: SELL");
return "sell";
} else {
log::info("agent", "Decision: HOLD");
return "hold";
}
}
Use ai::create_agent_coordinator() and
ai::create_workflow as in the API.
fn setup_coordinator() -> string {
let coordinator_id = ai::create_agent_coordinator();
log::info("agent", "Coordinator created");
return coordinator_id;
}
if (condition) { } with
parentheses.{ key: value } with colon;
keys can be identifier or string.ai::create_agent({ role: "...", capabilities: [...] }).log::info("tag", message) or
log::audit("tag", message).Create a test file that parses: use service, fn, let, if (condition).
// Create instance and call methods
let token = AITradingAgent::new();
token.create_agent("Trader1", "moderate", 1000000, 5);
let decision = token.make_trade_decision();
cargo run -- TradingAgent.dal
cargo testYou used:
ai::create_agent(config) with a
literal configai::create_agent_coordinator()if (condition) with parentheseslog::info("tag", message){ key: value } for config and
data