@balchemyai/agent-sdk 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/CHANGELOG.md +22 -1
  2. package/README.md +20 -284
  3. package/dist/agent-loop/llm-adapters/openai.d.ts.map +1 -1
  4. package/dist/agent-loop/llm-adapters/openai.js +6 -3
  5. package/dist/agent-loop/llm-adapters/openai.js.map +1 -1
  6. package/dist/agent-loop/types.d.ts +8 -138
  7. package/dist/agent-loop/types.d.ts.map +1 -1
  8. package/dist/index.d.ts +1 -33
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js +5 -72
  11. package/dist/index.js.map +1 -1
  12. package/docs/error-retry-strategy.md +4 -4
  13. package/docs/release-policy.md +1 -1
  14. package/package.json +2 -6
  15. package/dist/agent-loop/agent-loop.d.ts +0 -77
  16. package/dist/agent-loop/agent-loop.d.ts.map +0 -1
  17. package/dist/agent-loop/agent-loop.js +0 -1270
  18. package/dist/agent-loop/agent-loop.js.map +0 -1
  19. package/dist/agent-loop/decision-handler.d.ts +0 -38
  20. package/dist/agent-loop/decision-handler.d.ts.map +0 -1
  21. package/dist/agent-loop/decision-handler.js +0 -231
  22. package/dist/agent-loop/decision-handler.js.map +0 -1
  23. package/dist/agent-loop/llm-cost-tracker.d.ts +0 -27
  24. package/dist/agent-loop/llm-cost-tracker.d.ts.map +0 -1
  25. package/dist/agent-loop/llm-cost-tracker.js +0 -102
  26. package/dist/agent-loop/llm-cost-tracker.js.map +0 -1
  27. package/dist/agent-loop/model-router.d.ts +0 -35
  28. package/dist/agent-loop/model-router.d.ts.map +0 -1
  29. package/dist/agent-loop/model-router.js +0 -55
  30. package/dist/agent-loop/model-router.js.map +0 -1
  31. package/dist/agent-loop/rule-checker.d.ts +0 -26
  32. package/dist/agent-loop/rule-checker.d.ts.map +0 -1
  33. package/dist/agent-loop/rule-checker.js +0 -70
  34. package/dist/agent-loop/rule-checker.js.map +0 -1
  35. package/dist/agent-loop/telemetry-reporter.d.ts +0 -70
  36. package/dist/agent-loop/telemetry-reporter.d.ts.map +0 -1
  37. package/dist/agent-loop/telemetry-reporter.js +0 -221
  38. package/dist/agent-loop/telemetry-reporter.js.map +0 -1
  39. package/dist/agent-loop/webhook-receiver.d.ts +0 -41
  40. package/dist/agent-loop/webhook-receiver.d.ts.map +0 -1
  41. package/dist/agent-loop/webhook-receiver.js +0 -308
  42. package/dist/agent-loop/webhook-receiver.js.map +0 -1
  43. package/dist/auth/onboarding.d.ts +0 -12
  44. package/dist/auth/onboarding.d.ts.map +0 -1
  45. package/dist/auth/onboarding.js +0 -70
  46. package/dist/auth/onboarding.js.map +0 -1
  47. package/dist/auth/token-store.d.ts +0 -44
  48. package/dist/auth/token-store.d.ts.map +0 -1
  49. package/dist/auth/token-store.js +0 -67
  50. package/dist/auth/token-store.js.map +0 -1
  51. package/dist/mcp/mcp-client.d.ts +0 -174
  52. package/dist/mcp/mcp-client.d.ts.map +0 -1
  53. package/dist/mcp/mcp-client.js +0 -845
  54. package/dist/mcp/mcp-client.js.map +0 -1
  55. package/dist/streaming/sse-event-stream.d.ts +0 -72
  56. package/dist/streaming/sse-event-stream.d.ts.map +0 -1
  57. package/dist/streaming/sse-event-stream.js +0 -403
  58. package/dist/streaming/sse-event-stream.js.map +0 -1
  59. package/dist/types.d.ts +0 -162
  60. package/dist/types.d.ts.map +0 -1
  61. package/dist/types.js +0 -3
  62. package/dist/types.js.map +0 -1
  63. package/dist/utils/package-version.d.ts +0 -2
  64. package/dist/utils/package-version.d.ts.map +0 -1
  65. package/dist/utils/package-version.js +0 -54
  66. package/dist/utils/package-version.js.map +0 -1
  67. package/docs/BEHAVIOR_RULES.md +0 -184
  68. package/docs/DEPLOYMENT.md +0 -197
  69. package/docs/QUICKSTART.md +0 -139
  70. package/docs/examples/custom-strategy.yaml +0 -73
  71. package/docs/examples/dca-accumulator.yaml +0 -41
  72. package/docs/examples/memecoin-sniper.yaml +0 -47
  73. package/docs/examples/swing-trader.yaml +0 -50
  74. package/docs/partner-integration-checklist.md +0 -47
  75. package/docs/python-parity-backlog.md +0 -20
package/dist/types.d.ts DELETED
@@ -1,162 +0,0 @@
1
- export type AgentOnboardingMode = "siwe" | "walletless" | "legacy";
2
- export type AgentScope = "read" | "trade" | "manage";
3
- export type ProvisionedBot = {
4
- botId: string;
5
- publicId: string;
6
- name: string;
7
- };
8
- export type ProvisionedMcp = {
9
- endpoint: string;
10
- apiKey?: string;
11
- keyPrefix?: string;
12
- keyId?: string;
13
- };
14
- export type ProvisionedBaseWallet = {
15
- chainId: number;
16
- custodialWallet?: {
17
- address: string;
18
- walletId?: string;
19
- chainId?: number;
20
- };
21
- };
22
- export type IdentityAccess = {
23
- token: string;
24
- tokenType: "Bearer";
25
- expiresIn: number;
26
- expiresAt: string;
27
- kid: string;
28
- issuer: string;
29
- /** Scope granted at onboarding. "manage" is never issued at onboarding time. */
30
- scope: "read" | "trade";
31
- };
32
- export type OnboardingResponse = {
33
- /**
34
- * Legacy flag from canonical API envelopes.
35
- * SDK unwraps `{ success, data }`, so this is typically undefined.
36
- */
37
- success?: boolean;
38
- bot: ProvisionedBot;
39
- mcp: ProvisionedMcp;
40
- base: ProvisionedBaseWallet;
41
- onboardingInstructions?: string;
42
- onboarding?: {
43
- mode: AgentOnboardingMode;
44
- chainId: number;
45
- registryVerified: boolean;
46
- identityProvider?: string;
47
- };
48
- identityAccess?: IdentityAccess;
49
- };
50
- export type SiweNonceResponse = {
51
- message: string;
52
- nonce?: string;
53
- issuedAt?: string;
54
- expiresAt?: string;
55
- };
56
- export type OnboardWithSiweInput = {
57
- message: string;
58
- signature: string;
59
- agentId: string;
60
- /** Optional existing bot binding target (owned bot id). */
61
- botId?: string;
62
- /** Requested MCP key scope. Defaults to "trade" if omitted. */
63
- scope?: "read" | "trade";
64
- };
65
- export type OnboardWithIdentityInput = {
66
- provider: string;
67
- identityToken: string;
68
- agentId: string;
69
- /** Optional existing bot binding target (owned bot id). */
70
- botId?: string;
71
- chainId?: number;
72
- /** Requested MCP key scope. Defaults to "trade" if omitted. */
73
- scope?: "read" | "trade";
74
- };
75
- export type RequestSiweNonceInput = {
76
- address: string;
77
- chainId: number;
78
- domain: string;
79
- uri: string;
80
- statement?: string;
81
- };
82
- export type RevokeIdentityTokenInput = {
83
- identityToken: string;
84
- jti: string;
85
- ttlSeconds?: number;
86
- };
87
- export type IdentityTokenRevokeStatusInput = {
88
- identityToken: string;
89
- jti: string;
90
- };
91
- export type IdentityTokenRevokeResponse = {
92
- revoked: boolean;
93
- jti: string;
94
- };
95
- export type McpTool = {
96
- name: string;
97
- description?: string;
98
- inputSchema?: Record<string, unknown>;
99
- 'x-balchemy-category'?: string;
100
- 'x-balchemy-data-contract'?: Record<string, unknown>;
101
- 'x-balchemy-response'?: Record<string, unknown>;
102
- 'x-balchemy-requires-scope'?: 'read' | 'trade' | 'manage';
103
- 'x-balchemy-safety'?: 'read_only' | 'trade_guarded' | 'manage_step_up';
104
- 'x-balchemy-raw'?: boolean;
105
- };
106
- export type McpListToolsResponse = {
107
- tools: McpTool[];
108
- };
109
- export type McpTextContent = {
110
- type: "text";
111
- text: string;
112
- };
113
- export type McpCallToolResponse = {
114
- content: McpTextContent[];
115
- isError?: boolean;
116
- };
117
- /** Structured response from agent mode LLM calls */
118
- export type AgentResponse = {
119
- answer: string;
120
- confidence: number;
121
- sources?: string[];
122
- tool_calls?: Array<{
123
- tool_name: string;
124
- result: unknown;
125
- success: boolean;
126
- }>;
127
- follow_up_suggestions?: string[];
128
- };
129
- /** x-balchemy extension fields present in MCP tools/list entries */
130
- export type McpToolExtensions = {
131
- 'x-balchemy-category'?: string;
132
- 'x-balchemy-data-contract'?: Record<string, unknown>;
133
- 'x-balchemy-response'?: Record<string, unknown>;
134
- 'x-balchemy-requires-scope'?: 'read' | 'trade' | 'manage';
135
- 'x-balchemy-safety'?: 'read_only' | 'trade_guarded' | 'manage_step_up';
136
- 'x-balchemy-raw'?: boolean;
137
- 'x-balchemy-rate-limit'?: string;
138
- };
139
- /** Extended MCP tool with balchemy metadata from the tools/list response */
140
- export type McpToolWithMetadata = McpTool & {
141
- extensions?: McpToolExtensions;
142
- };
143
- export type AgentSdkConfig = {
144
- /**
145
- * Base URL for the Balchemy API, including the `/api` path segment.
146
- *
147
- * The SDK appends endpoint paths (e.g. `/public/erc8004/onboarding/identity`)
148
- * directly to this value, so it must NOT have a trailing slash.
149
- *
150
- * @example
151
- * // Local development
152
- * apiBaseUrl: "http://localhost:3000/api"
153
- *
154
- * @example
155
- * // Production
156
- * apiBaseUrl: "https://api.balchemy.ai/api"
157
- */
158
- apiBaseUrl: string;
159
- timeoutMs?: number;
160
- fetchFn?: typeof fetch;
161
- };
162
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,mBAAmB,GAAG,MAAM,GAAG,YAAY,GAAG,QAAQ,CAAC;AACnE,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,CAAC;AAErD,MAAM,MAAM,cAAc,GAAG;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,CAAC,EAAE;QAChB,OAAO,EAAE,MAAM,CAAC;QAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,CAAC;CACH,CAAC;AAE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,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B;;;;;;;;;;;;;OAaG;IACH,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,KAAK,CAAC;CACxB,CAAC"}
package/dist/types.js DELETED
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=types.js.map
package/dist/types.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export declare const BALCHEMY_AGENT_SDK_VERSION: string;
2
- //# sourceMappingURL=package-version.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"package-version.d.ts","sourceRoot":"","sources":["../../src/utils/package-version.ts"],"names":[],"mappings":"AAmBA,eAAO,MAAM,0BAA0B,EAAE,MAA6B,CAAC"}
@@ -1,54 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.BALCHEMY_AGENT_SDK_VERSION = void 0;
37
- const fs = __importStar(require("node:fs"));
38
- const path = __importStar(require("node:path"));
39
- /**
40
- * Package version read from this package's own package.json, the single source
41
- * of truth. Both `src/utils` and `dist/utils` sit two levels below the package
42
- * root, so the same relative path works under ts-jest and in the built output.
43
- */
44
- function readPackageVersion() {
45
- try {
46
- const manifest = JSON.parse(fs.readFileSync(path.join(__dirname, '..', '..', 'package.json'), 'utf8'));
47
- return typeof manifest.version === 'string' ? manifest.version : 'unknown';
48
- }
49
- catch {
50
- return 'unknown';
51
- }
52
- }
53
- exports.BALCHEMY_AGENT_SDK_VERSION = readPackageVersion();
54
- //# sourceMappingURL=package-version.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"package-version.js","sourceRoot":"","sources":["../../src/utils/package-version.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAA8B;AAC9B,gDAAkC;AAElC;;;;GAIG;AACH,SAAS,kBAAkB;IACzB,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CACzB,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,cAAc,CAAC,EAAE,MAAM,CAAC,CACjD,CAAC;QAC3B,OAAO,OAAO,QAAQ,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC;IAC7E,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAEY,QAAA,0BAA0B,GAAW,kBAAkB,EAAE,CAAC"}
@@ -1,184 +0,0 @@
1
- # Behavior Rules (BRL) — YAML Reference
2
-
3
- Behavior rules define how your agent trades. They are validated by the Balchemy
4
- backend before any trade is executed. The agent's LLM reads a compressed summary
5
- of your rules as context for every decision.
6
-
7
- ---
8
-
9
- ## Where to set rules
10
-
11
- **In `agent.config.yaml`** (inline):
12
-
13
- ```yaml
14
- behavior_rules:
15
- version: "1"
16
- preset: custom
17
- risk:
18
- max_single_trade_usd: 50
19
- ```
20
-
21
- **As a separate file** (referenced by path):
22
-
23
- ```yaml
24
- behavior_rules_path: ./my-rules.yaml
25
- ```
26
-
27
- ---
28
-
29
- ## Schema
30
-
31
- ### Top-level fields
32
-
33
- | Field | Type | Required | Description |
34
- |-------|------|----------|-------------|
35
- | `version` | string | Yes | Rule schema version. Always `"1"`. |
36
- | `preset` | string | No | Base preset to inherit (`memecoin-sniper`, `dca-accumulator`, `swing-trader`, `custom`). Inline fields override preset defaults. |
37
-
38
- ---
39
-
40
- ### `risk` — global safety limits
41
-
42
- ```yaml
43
- risk:
44
- max_single_trade_usd: 50 # Hard cap per trade. Default: 50
45
- max_daily_loss_usd: 200 # Pause trading after this daily loss. Default: 500
46
- max_open_positions: 5 # Max simultaneous positions. Default: 10
47
- pause_on_drawdown_pct: 20 # Pause if portfolio drops this % from peak. Default: none
48
- allowed_chains: [solana] # Restrict to specific chains. Default: [solana, base]
49
- ```
50
-
51
- ---
52
-
53
- ### `filters` — asset eligibility
54
-
55
- ```yaml
56
- filters:
57
- min_liquidity_usd: 10000 # Reject tokens below this liquidity. Default: 5000
58
- max_market_cap_usd: 10000000 # Reject tokens above this market cap. Default: none
59
- require_verified_contract: false # Only trade verified contracts. Default: false
60
- blocked_tokens: # Token addresses to never trade
61
- - "So11111111111111111111111111111111111111112"
62
- allowed_tokens: # Allowlist (if set, only these tokens trade)
63
- - "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"
64
- ```
65
-
66
- ---
67
-
68
- ### `entry` — trade entry conditions
69
-
70
- ```yaml
71
- entry:
72
- trigger: launch_signal # launch_signal | price_drop | rsi_signal | manual
73
- max_position_usd: 100 # Max USD per position. Default: 50
74
- slippage_bps: 200 # Max slippage in basis points. Default: 100
75
- min_confidence: 0.7 # Min LLM confidence score to enter. Default: 0.5
76
- indicators: [rsi, macd] # Required indicators for entry. Default: []
77
- rsi_oversold: 30 # Enter when RSI below this value. Default: 30
78
- ```
79
-
80
- ---
81
-
82
- ### `exit` — trade exit conditions
83
-
84
- ```yaml
85
- exit:
86
- take_profit_pct: 50 # Close position when up this %. Default: none
87
- stop_loss_pct: 25 # Close position when down this %. Default: none
88
- trailing_stop_pct: 10 # Trailing stop loss. Default: none
89
- max_hold_minutes: 120 # Force exit after this many minutes. Default: none
90
- min_hold_hours: 1 # Do not exit before this time. Default: 0
91
- max_hold_hours: 72 # Force exit after this time. Default: none
92
- ```
93
-
94
- ---
95
-
96
- ### `dca` — dollar-cost averaging (DCA preset)
97
-
98
- ```yaml
99
- dca:
100
- target_token: SOL # Token to accumulate
101
- amount_usd: 10 # USD per interval purchase
102
- interval_hours: 24 # Purchase interval in hours
103
- max_total_usd: 1000 # Stop after this total invested. Default: none
104
- ```
105
-
106
- ---
107
-
108
- ## Preset defaults
109
-
110
- ### memecoin-sniper
111
-
112
- ```yaml
113
- behavior_rules:
114
- version: "1"
115
- preset: memecoin-sniper
116
- filters:
117
- min_liquidity_usd: 10000
118
- max_market_cap_usd: 5000000
119
- require_verified_contract: false
120
- entry:
121
- trigger: launch_signal
122
- max_position_usd: 50
123
- slippage_bps: 300
124
- exit:
125
- take_profit_pct: 100
126
- stop_loss_pct: 50
127
- max_hold_minutes: 60
128
- ```
129
-
130
- ### dca-accumulator
131
-
132
- ```yaml
133
- behavior_rules:
134
- version: "1"
135
- preset: dca-accumulator
136
- dca:
137
- target_token: SOL
138
- amount_usd: 10
139
- interval_hours: 24
140
- max_total_usd: 1000
141
- risk:
142
- max_single_trade_usd: 10
143
- pause_on_drawdown_pct: 30
144
- ```
145
-
146
- ### swing-trader
147
-
148
- ```yaml
149
- behavior_rules:
150
- version: "1"
151
- preset: swing-trader
152
- entry:
153
- indicators: [rsi, macd]
154
- rsi_oversold: 30
155
- max_position_usd: 200
156
- slippage_bps: 100
157
- exit:
158
- take_profit_pct: 20
159
- stop_loss_pct: 10
160
- min_hold_hours: 2
161
- max_hold_hours: 72
162
- ```
163
-
164
- ---
165
-
166
- ## Enforcement
167
-
168
- Rules are enforced at three levels:
169
-
170
- 1. **Pre-check** — asset filters applied before the LLM is called (no LLM cost)
171
- 2. **LLM context** — compressed rule summary injected into every decision prompt
172
- 3. **Post-check** — Balchemy backend validates trade parameters against rules before execution
173
-
174
- If a trade violates a rule at any level, it is rejected with an error logged via `onError`.
175
-
176
- ---
177
-
178
- ## Tips
179
-
180
- - Start with a preset and override only the fields you need
181
- - Keep `max_single_trade_usd` low (≤ $50) until you trust your strategy
182
- - Use `blocked_tokens` to exclude known scams
183
- - Use `min_confidence` to reduce false positives when LLM is uncertain
184
- - Monitor LLM cost with `onStatusChange` — `llmCostToday` / `maxDailyLlmCost`
@@ -1,197 +0,0 @@
1
- # Deployment Guide
2
-
3
- Your agent runs as a long-lived Node.js process. The recommended deployment targets
4
- are a personal VPS ($4–7/mo) or a managed container platform (Railway, Render).
5
-
6
- ---
7
-
8
- ## Option A: Docker on a VPS (recommended)
9
-
10
- This is the most reliable option. The agent runs in a Docker container that restarts
11
- automatically on failure or reboot.
12
-
13
- ### Requirements
14
-
15
- - Any Linux VPS with Docker installed (Ubuntu 22.04 LTS recommended)
16
- - At least 256 MB RAM, 1 vCPU
17
- - Providers: DigitalOcean, Hetzner, Vultr, Linode — all work fine
18
-
19
- ### Steps
20
-
21
- **1. On your local machine:**
22
-
23
- ```bash
24
- npx balchemy # Setup wizard
25
- npx balchemy docker # Generate Dockerfile + docker-compose.yml
26
- ```
27
-
28
- This creates:
29
- ```
30
- Dockerfile
31
- docker-compose.yml
32
- .env.example ← copy to .env, fill in credentials
33
- agent.config.yaml ← edit behavior_rules as needed
34
- ```
35
-
36
- **2. Copy files to your VPS:**
37
-
38
- ```bash
39
- scp Dockerfile docker-compose.yml agent.config.yaml .env user@your-vps:/home/user/agent/
40
- ```
41
-
42
- **3. On your VPS:**
43
-
44
- ```bash
45
- cd /home/user/agent
46
- docker compose up -d
47
- docker compose logs -f # Watch logs
48
- ```
49
-
50
- **4. Verify the agent is running:**
51
-
52
- ```bash
53
- docker compose ps
54
- # balchemy-agent Up (healthy)
55
- ```
56
-
57
- ### Managing the agent
58
-
59
- ```bash
60
- docker compose stop # Graceful stop
61
- docker compose start # Start after stop
62
- docker compose restart # Restart
63
- docker compose logs -f # Tail logs
64
- docker compose pull && docker compose up -d # Update
65
- ```
66
-
67
- ### Updating config without rebuilding
68
-
69
- The `agent.config.yaml` is mounted read-only into the container. Edit it on the
70
- VPS and restart:
71
-
72
- ```bash
73
- nano agent.config.yaml
74
- docker compose restart
75
- ```
76
-
77
- ---
78
-
79
- ## Option B: Railway
80
-
81
- Railway provides free-tier hosting for small containers.
82
-
83
- 1. Push your agent directory to a GitHub repo (exclude `.env`)
84
- 2. Create a new Railway project → Deploy from GitHub
85
- 3. Set environment variables in Railway dashboard:
86
- - `MCP_ENDPOINT`, `BALCHEMY_API_KEY`, `LLM_API_KEY`
87
- 4. Railway auto-detects `Dockerfile` and builds the image
88
- 5. Set restart policy to "Always"
89
-
90
- ---
91
-
92
- ## Option C: Render
93
-
94
- Similar to Railway. Use Render's "Background Worker" service type (not Web Service).
95
-
96
- 1. Connect your GitHub repo
97
- 2. Select "Background Worker" (no port required)
98
- 3. Set environment variables in Render dashboard
99
- 4. Set "Restart Policy" to "Always"
100
-
101
- ---
102
-
103
- ## Option D: systemd daemon (Linux without Docker)
104
-
105
- If you prefer to run the agent directly as a system service:
106
-
107
- **1. Install locally in the agent directory:**
108
-
109
- ```bash
110
- cd /home/ubuntu/agent
111
- npm init -y
112
- npm install --omit=dev balchemy@0.8.0 @balchemyai/agent-sdk@0.8.0
113
- ```
114
-
115
- **2. Create a systemd unit file:**
116
-
117
- ```ini
118
- # /etc/systemd/system/balchemy.service
119
- [Unit]
120
- Description=Balchemy Trading Agent
121
- After=network.target
122
-
123
- [Service]
124
- Type=simple
125
- User=ubuntu
126
- WorkingDirectory=/home/ubuntu/agent
127
- ExecStart=/home/ubuntu/agent/node_modules/.bin/balchemy start /home/ubuntu/agent/agent.config.yaml
128
- EnvironmentFile=/home/ubuntu/agent/.env
129
- Restart=always
130
- RestartSec=10
131
- StandardOutput=journal
132
- StandardError=journal
133
-
134
- [Install]
135
- WantedBy=multi-user.target
136
- ```
137
-
138
- **3. Enable and start:**
139
-
140
- ```bash
141
- sudo systemctl daemon-reload
142
- sudo systemctl enable balchemy
143
- sudo systemctl start balchemy
144
- sudo journalctl -u balchemy -f
145
- ```
146
-
147
- ---
148
-
149
- ## Security checklist
150
-
151
- - `.env` must have permissions `600`: `chmod 600 .env`
152
- - Never expose `agent.config.yaml` or `.env` via HTTP
153
- - Use a non-root user inside the container (default Dockerfile uses `node` user)
154
- - Rotate API keys regularly in Hub > Agents > API Keys
155
- - Set `max_single_trade_usd` and `max_daily_loss_usd` to safe values before deploying
156
-
157
- ---
158
-
159
- ## Monitoring
160
-
161
- The agent logs to stdout in this format:
162
-
163
- ```
164
- [agent] status=running events=42 decisions=7 trades=2 llmCost=$0.0120/5.00
165
- [agent] decision action=buy token=SOL amount=10 confidence=0.87
166
- [agent] error: trade_command failed: insufficient balance
167
- ```
168
-
169
- To forward logs to a log aggregator (e.g., Loki, Datadog):
170
-
171
- ```yaml
172
- # In docker-compose.yml
173
- logging:
174
- driver: loki
175
- options:
176
- loki-url: "http://your-loki-host:3100/loki/api/v1/push"
177
- loki-labels: "service=balchemy-agent"
178
- ```
179
-
180
- ---
181
-
182
- ## Troubleshooting
183
-
184
- **Agent exits immediately:**
185
- - Check `.env` — all required vars must be set
186
- - Check `agent.config.yaml` — `mcp_endpoint` and `api_key` are required
187
- - Run `docker compose logs` to see the error
188
-
189
- **Agent starts but makes no decisions:**
190
- - Verify your API key has `trade` scope (Hub > API Keys > Scopes)
191
- - Check that setup is complete and the backend reports the expected runtime mode
192
- - Lower `min_confidence` in `behavior_rules`
193
-
194
- **Budget exhausted quickly:**
195
- - Reduce `max_daily_usd` in `llm` config
196
- - Switch to a cheaper model (`claude-haiku-4-5` or `gpt-4o-mini`)
197
- - Add more specific filters to avoid processing low-quality signals