-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: tracing framework #275
base: sif-dev
Are you sure you want to change the base?
Changes from all commits
4d4289b
a35e7f7
810ac87
5a9f7a6
c121ea0
af0c0ef
4c4263b
b55fc32
321fc36
7b4682e
ceca1e2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,6 +131,15 @@ CREATE TABLE IF NOT EXISTS cache ( | |
PRIMARY KEY ("key", "agentId") | ||
); | ||
|
||
CREATE TABLE IF NOT EXISTS traces ( | ||
"id" BIGSERIAL NOT NULL, | ||
"run" UUID, | ||
"time" TIMESTAMP NOT NULL, | ||
"name" VARCHAR(80) NOT NULL, | ||
"data" JSON, | ||
PRIMARY KEY ("id") | ||
); | ||
Comment on lines
+134
to
+141
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We also add a category field like we discussed for the few types of logging we discussed: before llm call, interpolated prompt, prompt output, action result. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The idea here is that |
||
|
||
DO $$ | ||
DECLARE | ||
vector_dim INTEGER; | ||
|
@@ -164,5 +173,8 @@ CREATE INDEX IF NOT EXISTS idx_knowledge_original ON knowledge("originalId"); | |
CREATE INDEX IF NOT EXISTS idx_knowledge_created ON knowledge("agentId", "createdAt"); | ||
CREATE INDEX IF NOT EXISTS idx_knowledge_shared ON knowledge("isShared"); | ||
CREATE INDEX IF NOT EXISTS idx_knowledge_embedding ON knowledge USING ivfflat (embedding vector_cosine_ops); | ||
CREATE INDEX IF NOT EXISTS idx_traces_1 ON traces ("run", "name", "time"); | ||
CREATE INDEX IF NOT EXISTS idx_traces_2 ON traces ("name", "run", "time"); | ||
CREATE INDEX IF NOT EXISTS idx_traces_3 ON traces ("time", "name"); | ||
|
||
COMMIT; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { AsyncLocalStorage } from "async_hooks"; | ||
import { inspect } from "util"; | ||
import { v4 as uuidv4 } from "uuid"; | ||
|
||
export type ITrace = (run: string | null, time: Date, name: string, data: any) => void; | ||
|
||
export function generateRunUUID(): string { | ||
return uuidv4(); | ||
} | ||
|
||
export class Instrumentation { | ||
private static store = new AsyncLocalStorage<Instrumentation>(); | ||
private static tracer: ITrace = null; | ||
private run: string = null; | ||
|
||
static init(tracer: ITrace) { | ||
this.tracer = tracer; | ||
} | ||
|
||
static trace(name: string, data: any) { | ||
if (!this.tracer) return; | ||
var jsonPayload; | ||
try { | ||
jsonPayload = JSON.stringify(data); | ||
} catch (error) { | ||
name = `ERROR: ${name}`; | ||
jsonPayload = {ok: false, name: name, error: `${error}, inspect: ${inspect(data)}`}; | ||
console.log(`Could not convert object to JSON for ${name}. Please select individual fields that are serializable.`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. eliza log everywhere There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is intentional because (1) I don't want to see the colors, (2) I need the raw printout, and (3) this simply does not belong in the same category as logging. The purpose for this is to catch the objects that fail to JSONify, and then selectively pick the properties we need. When we are done, we should not need this anymore anyway. |
||
console.log(data); | ||
} | ||
const instance = this.store.getStore(); | ||
const run = instance.run; | ||
const time = new Date(); | ||
(async () => { | ||
await this.tracer(run, time, name, jsonPayload); | ||
})(); | ||
} | ||
|
||
static run(f: () => any, run?: string | null): any { | ||
const i = new Instrumentation(); | ||
if (run === undefined) run = null; | ||
if (!run) run = uuidv4(); | ||
i.run = run; | ||
return this.store.run(i, f); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import { embed, getEmbeddingZeroVector } from "./embedding.ts"; | ||
import { Instrumentation } from "./instrumentation.ts"; | ||
import elizaLogger from "./logger.ts"; | ||
import { | ||
IAgentRuntime, | ||
|
@@ -97,7 +98,7 @@ export class MemoryManager implements IMemoryManager { | |
start?: number; | ||
end?: number; | ||
}): Promise<Memory[]> { | ||
return await this.runtime.databaseAdapter.getMemories({ | ||
const result = await this.runtime.databaseAdapter.getMemories({ | ||
roomId, | ||
count, | ||
unique, | ||
|
@@ -106,6 +107,8 @@ export class MemoryManager implements IMemoryManager { | |
start, | ||
end, | ||
}); | ||
Instrumentation.trace("MemoryManager.getMemories", {roomId: roomId, count: count, result: result}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to be clear for now you don't need to store all these values. Please goo into a PLUGIN /plugin-coinbase/plugins/trade.ts and please add 4 calls to Instrumentation as we discussed the value of composeState, the interpolated prompt so value from composeContext, the output of the LLM, the action and output of the action so 4 calls (this is an example we need to do the same thing for each of these) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So we're testing coinbase plugin first? Would be nice if somebody answered my questions first. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah that would be a great start! Sorry I think I mentioned in on our call that day - sorry if I wasn't clear |
||
return result; | ||
} | ||
|
||
async getCachedEmbeddings(content: string): Promise< | ||
|
@@ -187,6 +190,7 @@ export class MemoryManager implements IMemoryManager { | |
this.tableName, | ||
unique | ||
); | ||
Instrumentation.trace("MemoryManager.createMemory", {memoryId: memory.id, text: memory.content.text}) | ||
} | ||
|
||
async getMemoriesByRoomIds(params: { roomIds: UUID[], limit?: number; }): Promise<Memory[]> { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason we are removing this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're not removing it, just wrapping, this is how the context functions are designed.