-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from autonomys/auto-chain-agent
Add auto chain agent
- Loading branch information
Showing
18 changed files
with
4,456 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,3 +42,5 @@ node_modules/ | |
# SQLite database | ||
*.sqlite | ||
*.sqlite-journal | ||
|
||
resources/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
AGENTS_PORT=3001 | ||
BACKEND_PORT=8001 | ||
FRONTEND_PORT=3031 | ||
OPENAI_API_KEY=<your_openai_api_key_here> | ||
BACKEND_SERVICE_URL=http://localhost:8001 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Dependencies | ||
node_modules | ||
.pnp | ||
.pnp.js | ||
|
||
# Build outputs | ||
dist | ||
build | ||
out | ||
|
||
# Environment files | ||
.env | ||
.env.local | ||
.env.*.local | ||
|
||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# Editor directories | ||
.idea | ||
.vscode | ||
*.swp | ||
*.swo | ||
|
||
# OS files | ||
.DS_Store | ||
Thumbs.db | ||
|
||
# Database | ||
*.sqlite | ||
*.sqlite3 | ||
|
||
# Test coverage | ||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
OPENAI_API_KEY=<your-openai-api-key> | ||
ANTHROPIC_API_KEY=<your-anthropic-api-key> | ||
TEST_MNEMONIC=<test-mnemonic> | ||
AGENTS_PORT=3000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"watch": ["src"], | ||
"ext": "ts,json", | ||
"ignore": ["src/**/*.spec.ts"], | ||
"exec": "ts-node ./src/index.ts" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"name": "@auto-chain/agents", | ||
"version": "1.0.0", | ||
"private": true, | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"scripts": { | ||
"build": "tsc", | ||
"dev": "tsc && nodemon", | ||
"start": "node dist/index.js" | ||
}, | ||
"dependencies": { | ||
"@autonomys/auto-consensus": "0.7.3", | ||
"@autonomys/auto-drive": "0.7.3", | ||
"@autonomys/auto-utils": "0.7.3", | ||
"@langchain/anthropic": "0.3.7", | ||
"@langchain/community": "0.3.11", | ||
"@langchain/core": "0.3.3", | ||
"@langchain/langgraph": "0.2.8", | ||
"@langchain/openai": "0.3.1", | ||
"axios": "^1.7.7", | ||
"dotenv": "^16.4.1", | ||
"express": "5.0.0", | ||
"sqlite": "^5.1.1", | ||
"sqlite3": "^5.1.7", | ||
"winston": "^3.14.2", | ||
"zod": "^3.23.8" | ||
}, | ||
"devDependencies": { | ||
"@types/express": "5.0.0", | ||
"@types/node": "22.6.1", | ||
"nodemon": "^3.0.1", | ||
"ts-node": "^10.9.2", | ||
"typescript": "^5.3.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import dotenv from 'dotenv'; | ||
|
||
dotenv.config(); | ||
|
||
export const config = { | ||
port: process.env.AGENTS_PORT || 3000, | ||
anthropicApiKey: process.env.ANTHROPIC_API_KEY, | ||
openaiApiKey: process.env.OPENAI_API_KEY, | ||
environment: process.env.NODE_ENV || 'development', | ||
autoConsensus: { | ||
apiKey: process.env.AUTO_CONSENSUS_API_KEY, | ||
}, | ||
llmConfig: { | ||
temperature: 0.4, | ||
maxTokens: 1500 | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import express from 'express'; | ||
import { chainRouter } from './routes/chainAgentRoutes'; | ||
import logger from './logger'; | ||
import { config } from './config'; | ||
|
||
const app = express(); | ||
const port = config.port || 3000; | ||
|
||
app.use(express.json()); | ||
|
||
// Routes | ||
app.use('/chainagent', chainRouter); | ||
|
||
// Health check route | ||
app.get('/', (req, res) => { | ||
logger.info('Health check request received'); | ||
res.send('Blockchain Agent Service is running!'); | ||
}); | ||
|
||
// Error handling middleware | ||
app.use((err: Error, req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
logger.error('Unhandled error:', err); | ||
res.status(500).json({ | ||
error: 'An error occurred while processing your request', | ||
details: err.message | ||
}); | ||
}); | ||
|
||
app.listen(port, () => { | ||
logger.info(`Blockchain agent service is running on http://localhost:${port}`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import winston from 'winston'; | ||
import { config } from './config'; | ||
|
||
const logger = winston.createLogger({ | ||
level: 'info', | ||
format: winston.format.combine( | ||
winston.format.timestamp(), | ||
winston.format.colorize(), | ||
winston.format.printf(({ level, message, timestamp }) => { | ||
return `${timestamp} [${level}]: ${message}`; | ||
}) | ||
), | ||
transports: [ | ||
new winston.transports.File({ | ||
filename: 'error.log', | ||
level: 'error', | ||
format: winston.format.json() | ||
}), | ||
new winston.transports.File({ | ||
filename: 'combined.log', | ||
format: winston.format.json() | ||
}) | ||
] | ||
}); | ||
|
||
if (config.environment !== 'production') { | ||
logger.add(new winston.transports.Console({ | ||
format: winston.format.combine( | ||
winston.format.colorize(), | ||
winston.format.timestamp(), | ||
winston.format.printf(({ level, message, timestamp }) => { | ||
return `${timestamp} [${level}]: ${message}`; | ||
}) | ||
) | ||
})); | ||
} | ||
|
||
export default logger; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import express from 'express'; | ||
import { blockchainAgent } from '../services/chainAgent'; | ||
import logger from '../logger'; | ||
|
||
const router = express.Router(); | ||
|
||
router.post('/', (req, res, next) => { | ||
logger.info('Received blockchain request:', req.body); | ||
(async () => { | ||
try { | ||
const { message } = req.body; | ||
|
||
if (!message) { | ||
logger.warn('Missing message field'); | ||
return res.status(400).json({ error: 'Message is required' }); | ||
} | ||
|
||
const result = await blockchainAgent.handleMessage({ | ||
message | ||
}); | ||
|
||
res.json({ | ||
threadId: result.threadId, | ||
response: result.response, | ||
toolCalls: result.toolCalls | ||
}); | ||
} catch (error) { | ||
logger.error('Error in blockchain endpoint:', error); | ||
next(error); | ||
} | ||
})(); | ||
}); | ||
|
||
router.get('/:threadId/state', (req, res, next) => { | ||
logger.info('Received request to get blockchain thread state:', req.params.threadId); | ||
(async () => { | ||
try { | ||
const threadId = req.params.threadId; | ||
const threadState = await blockchainAgent.getThreadState(threadId); | ||
|
||
if (!threadState) { | ||
return res.status(404).json({ | ||
error: 'Thread not found' | ||
}); | ||
} | ||
|
||
res.json({ | ||
threadId, | ||
state: { | ||
messages: threadState.state.messages, | ||
toolCalls: threadState.state.toolCalls, | ||
lastOutput: threadState.lastOutput | ||
} | ||
}); | ||
} catch (error) { | ||
logger.error('Error getting thread state:', error); | ||
next(error); | ||
} | ||
})(); | ||
}); | ||
|
||
export const chainRouter = router; |
Oops, something went wrong.