-
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 #21 from autonomys/auto-chain-enhance
Auto chain agent -> memory enabled + enhanced frontend
- Loading branch information
Showing
27 changed files
with
1,963 additions
and
1,041 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 |
---|---|---|
|
@@ -33,6 +33,8 @@ Thumbs.db | |
# Database | ||
*.sqlite | ||
*.sqlite3 | ||
|
||
summary-differences.json | ||
summary-*.json | ||
diffs/ | ||
# 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
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
OPENAI_API_KEY=<your-openai-api-key> | ||
ANTHROPIC_API_KEY=<your-anthropic-api-key> | ||
TEST_MNEMONIC=<test-mnemonic> | ||
AGENT_KEY=<mnemonic> | ||
AGENTS_PORT=3000 | ||
DSN_API_KEY=<your-dsn-api-key> |
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
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 |
---|---|---|
@@ -1,17 +1,20 @@ | ||
import dotenv from 'dotenv'; | ||
import path from 'path'; | ||
|
||
dotenv.config(); | ||
|
||
export const config = { | ||
CHECK_INTERVAL: 20 * 1000, | ||
SUMMARY_DIR: path.join(process.cwd(), 'diffs'), | ||
SUMMARY_FILE_PATH : path.join(process.cwd(), 'diffs', 'summary-differences.json'), | ||
DIFF_FILE_PREFIX: 'summary-diff', | ||
LLM_MODEL: "gpt-4o-mini", | ||
TEMPERATURE: 0.5, | ||
AGENT_KEY: process.env.AGENT_KEY || '//Alice', | ||
NETWORK: 'taurus', | ||
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 | ||
} | ||
dsnApiKey: process.env.DSN_API_KEY, | ||
}; |
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
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,30 @@ | ||
import sqlite3 from 'sqlite3'; | ||
import { open } from 'sqlite'; | ||
import logger from '../../logger'; | ||
|
||
export const initializeDb = async (dbPath: string) => { | ||
logger.info('Initializing SQLite database at:', dbPath); | ||
const db = await open({ | ||
filename: dbPath, | ||
driver: sqlite3.Database | ||
}); | ||
|
||
await db.exec(` | ||
CREATE TABLE IF NOT EXISTS threads ( | ||
thread_id TEXT PRIMARY KEY, | ||
messages TEXT NOT NULL, | ||
tool_calls TEXT, | ||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP, | ||
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP | ||
); | ||
CREATE TABLE IF NOT EXISTS summary_uploads ( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
upload_id TEXT NOT NULL, | ||
CID TEXT NULL, | ||
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP | ||
); | ||
`); | ||
|
||
return db; | ||
}; |
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,3 @@ | ||
import { createThreadStorage } from './threadStorage'; | ||
|
||
export type ThreadStorage = ReturnType<typeof createThreadStorage>; |
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,33 @@ | ||
import { BaseMessage, MessageContent } from '@langchain/core/messages'; | ||
|
||
export interface ThreadState { | ||
messages: BaseMessage[]; | ||
toolCalls: Array<{ | ||
id: string; | ||
type: string; | ||
function: { | ||
name: string; | ||
arguments: string; | ||
}; | ||
result?: string; | ||
}>; | ||
} | ||
export interface ConversationState { | ||
isInitialLoad: boolean; | ||
needsHistoryRebuild: boolean; | ||
} | ||
|
||
export interface SummaryDifference { | ||
timestamp: string; | ||
threadId: string; | ||
previousSummary: string | MessageContent; | ||
currentSummary: string | MessageContent; | ||
difference: string | MessageContent; | ||
previousCID?: string; | ||
} | ||
|
||
export interface SummaryState { | ||
lastCheck: string; | ||
differences: SummaryDifference[]; | ||
} | ||
|
67 changes: 67 additions & 0 deletions
67
auto-chain-agent/agents/src/services/thread/summaryState.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,67 @@ | ||
import fs from 'fs'; | ||
import logger from '../../logger'; | ||
import { SummaryState } from './interface'; | ||
import { saveDiffFile } from './utils'; | ||
import { config } from '../../config'; | ||
|
||
export const loadSummaryState = async (): Promise<SummaryState> => { | ||
try { | ||
if (fs.existsSync(config.SUMMARY_FILE_PATH)) { | ||
const data = await fs.promises.readFile(config.SUMMARY_FILE_PATH, 'utf8'); | ||
return JSON.parse(data); | ||
} | ||
return { | ||
lastCheck: new Date().toISOString(), | ||
differences: [] | ||
}; | ||
} catch (error) { | ||
logger.error('Error loading summary state:', error); | ||
return { | ||
lastCheck: new Date().toISOString(), | ||
differences: [] | ||
}; | ||
} | ||
}; | ||
|
||
export const saveSummaryState = async (state: SummaryState) => { | ||
try { | ||
const existingState = await (async (): Promise<SummaryState | null> => { | ||
if (fs.existsSync(config.SUMMARY_FILE_PATH)) { | ||
const existingData = await fs.promises.readFile(config.SUMMARY_FILE_PATH, 'utf8'); | ||
return JSON.parse(existingData); | ||
} | ||
return null; | ||
})(); | ||
|
||
// Save main summary file | ||
await fs.promises.writeFile( | ||
config.SUMMARY_FILE_PATH, | ||
JSON.stringify(state, null, 2), | ||
'utf8' | ||
); | ||
|
||
// Only create and upload diff file if there are actual changes | ||
if (!existingState || | ||
JSON.stringify(existingState.differences) !== JSON.stringify(state.differences)) { | ||
|
||
// Get new differences since last state | ||
const newDifferences = existingState | ||
? state.differences.filter(diff => | ||
!existingState.differences.some( | ||
existingDiff => existingDiff.timestamp === diff.timestamp | ||
) | ||
) | ||
: state.differences; | ||
|
||
if (newDifferences.length > 0) { | ||
await saveDiffFile(newDifferences); | ||
} | ||
} else { | ||
logger.info('No changes detected in summary differences, skipping diff file creation'); | ||
} | ||
} catch (error) { | ||
logger.error('Error saving summary state:', error); | ||
throw error; | ||
} | ||
}; | ||
|
Oops, something went wrong.