cornerstone-autonomous-agent 1.3.0 → 2.1.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.
- package/.env.example +3 -8
- package/LICENSE.md +384 -384
- package/README.md +91 -116
- package/adapters/local/README.md +2 -2
- package/adapters/openai/openapi.yaml +3 -3
- package/adapters/openclaw/SKILL.md +40 -29
- package/package.json +7 -7
- package/skills/README.md +1 -1
- package/skills/autonomous-agent/SKILL.md +41 -30
- package/src/agent/agent.js +77 -53
- package/src/agent/tools/localTools.js +260 -259
- package/src/agent/tools/mcpTools.js +150 -150
- package/src/cli.js +57 -0
- package/src/lib/aptos/signPayment.js +1 -1
- package/src/lib/evm/signPayment.js +1 -1
- package/src/lib/mcp/client.js +35 -17
- package/src/run-agent.js +2 -2
- package/src/show-agent-addresses.js +33 -33
package/src/agent/agent.js
CHANGED
|
@@ -1,53 +1,77 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* LangChain.js ReAct
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { createReactAgent } from '@langchain/langgraph/prebuilt';
|
|
6
|
-
import { createLLM } from './llm.js';
|
|
7
|
-
import { createMcpTools } from './tools/mcpTools.js';
|
|
8
|
-
import { createLocalTools } from './tools/localTools.js';
|
|
9
|
-
|
|
10
|
-
const SYSTEM_MESSAGE = `You are an
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
1
|
+
/**
|
|
2
|
+
* LangChain.js ReAct runner for the skill: MCP tools + local tools, Hugging Face LLM.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { createReactAgent } from '@langchain/langgraph/prebuilt';
|
|
6
|
+
import { createLLM } from './llm.js';
|
|
7
|
+
import { createMcpTools } from './tools/mcpTools.js';
|
|
8
|
+
import { createLocalTools } from './tools/localTools.js';
|
|
9
|
+
|
|
10
|
+
const SYSTEM_MESSAGE = `You are an agent with a skill that provides tools for wallet management and x402-paid MCP tools (predictions, backtests, bank linking, scores). Payment is automatic — just call the tool.
|
|
11
|
+
|
|
12
|
+
## ALWAYS DO FIRST
|
|
13
|
+
Before any paid or wallet action, call get_wallet_addresses (no args). It returns:
|
|
14
|
+
{ aptos: [{ address, network }], evm: [{ address, network }] }
|
|
15
|
+
- If aptos is empty and you need Aptos tools: create_aptos_wallet -> credit_aptos_wallet -> tell user to whitelist at https://arnstein.ch/flow.html
|
|
16
|
+
- If evm is empty and you need EVM tools: create_evm_wallet -> fund_evm_wallet -> tell user to whitelist at https://arnstein.ch/flow.html
|
|
17
|
+
- If wallets exist: check balance before paid calls. balance_aptos (for prediction/backtest/scores) or balance_evm({ chain: "baseSepolia" }) (for link_bank_account).
|
|
18
|
+
|
|
19
|
+
## TOOLS
|
|
20
|
+
|
|
21
|
+
Wallet tools:
|
|
22
|
+
- get_wallet_addresses() -> { aptos: [...], evm: [...] }
|
|
23
|
+
- create_aptos_wallet({ force?, network? }) -> { success, address, network }
|
|
24
|
+
- create_evm_wallet({ force?, network? }) -> { success, address, network }
|
|
25
|
+
- credit_aptos_wallet({ amount_octas? }) -> devnet: funds directly; testnet: returns faucet_url + instructions
|
|
26
|
+
- fund_evm_wallet() -> returns faucet_url + address (manual funding)
|
|
27
|
+
- balance_aptos() -> { address, balances: { usdc, apt } }
|
|
28
|
+
- balance_evm({ chain? }) -> { address, chain, balance, symbol }. Chains: base, baseSepolia, ethereum, polygon, arbitrum, optimism
|
|
29
|
+
|
|
30
|
+
Paid MCP tools (payment handled for you — just call them):
|
|
31
|
+
- run_prediction({ symbol, horizon? }) — stock prediction, ~6c USDC. Example: run_prediction({ symbol: "AAPL", horizon: 30 })
|
|
32
|
+
- run_backtest({ symbol, startDate?, endDate?, strategy? }) — backtest, ~6c. Dates "YYYY-MM-DD", strategy default "chronos"
|
|
33
|
+
- link_bank_account() — Plaid bank link, ~5c on Base. Needs funded EVM wallet (baseSepolia for testnet)
|
|
34
|
+
- get_agent_reputation_score({ agent_address?, payer_wallet? }) — reputation score
|
|
35
|
+
- get_borrower_score({ agent_address?, payer_wallet? }) — borrower score
|
|
36
|
+
- get_agent_reputation_score_by_email({ email, payer_wallet? }) — by email (needs SCORE_BY_EMAIL_ENABLED)
|
|
37
|
+
- get_borrower_score_by_email({ email, payer_wallet? }) — by email
|
|
38
|
+
|
|
39
|
+
## ERROR RECOVERY
|
|
40
|
+
- "No Aptos/EVM wallet" -> create the missing wallet
|
|
41
|
+
- "already exist" -> use existing wallet, or pass force: true to add another
|
|
42
|
+
- "Payment verification failed" -> insufficient funds; check balance, tell user to fund
|
|
43
|
+
- "403" / "not allowlisted" -> tell user to whitelist at https://arnstein.ch/flow.html
|
|
44
|
+
- Timeout -> retry once`;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Create agent graph: llm + tools (MCP + local).
|
|
48
|
+
* @param {{ llm?: import('@langchain/core/language_models/chat_models').BaseChatModel; tools?: import('@langchain/core/tools').StructuredToolInterface[] }} options - llm and tools (if omitted, created from env and mcpClient)
|
|
49
|
+
* @param {{ callTool: (name: string, args: Object) => Promise<Object> }} [options.mcpClient] - required if tools not provided
|
|
50
|
+
* @returns {Promise<{ agent: import('@langchain/langgraph').CompiledStateGraph; runAgent: (message: string) => Promise<Object> }>}
|
|
51
|
+
*/
|
|
52
|
+
export async function createAgent(options = {}) {
|
|
53
|
+
const llm = options.llm || createLLM();
|
|
54
|
+
let tools = options.tools;
|
|
55
|
+
if (!tools && options.mcpClient) {
|
|
56
|
+
tools = [...createMcpTools(options.mcpClient), ...createLocalTools()];
|
|
57
|
+
}
|
|
58
|
+
if (!tools) {
|
|
59
|
+
throw new Error('Provide options.tools or options.mcpClient to createAgent.');
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const agent = createReactAgent({
|
|
63
|
+
llm,
|
|
64
|
+
tools,
|
|
65
|
+
stateModifier: (state) => [{ role: 'system', content: SYSTEM_MESSAGE }, ...(state.messages || [])],
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
async function runAgent(userMessage) {
|
|
69
|
+
const result = await agent.invoke(
|
|
70
|
+
{ messages: [{ role: 'user', content: userMessage }] },
|
|
71
|
+
{ recursionLimit: 50 }
|
|
72
|
+
);
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return { agent, runAgent };
|
|
77
|
+
}
|