MCPcopy Create free account
hub / github.com/Roy3838/Observer / getRecentAgentRuns

Function getRecentAgentRuns

app/src/utils/agentParser.ts:236–259  ·  view source on GitHub ↗

* Gets recent runs for an agent from IterationStore * @param agentId Agent ID * @param count Number of recent runs to fetch * @returns Array of recent iteration data

(agentId: string, count: number)

Source from the content-addressed store, hash-verified

234 * @returns Array of recent iteration data
235 */
236async function getRecentAgentRuns(agentId: string, count: number): Promise<IterationData[]> {
237 // Get current session runs
238 const currentRuns = IterationStore.getIterationsForAgent(agentId);
239
240 // Get historical runs if we need more
241 if (currentRuns.length >= count) {
242 return currentRuns.slice(-count); // Get last N runs
243 }
244
245 // Need to get historical data
246 const historicalSessions = await IterationStore.getHistoricalSessions(agentId);
247 const allRuns: IterationData[] = [...currentRuns];
248
249 // Add runs from most recent sessions until we have enough
250 for (const session of historicalSessions) {
251 const needed = count - allRuns.length;
252 const sessionRuns = session.iterations.slice(-needed); // Take LAST needed iterations
253 allRuns.unshift(...sessionRuns);
254
255 if (allRuns.length >= count) break;
256 }
257
258 return allRuns.slice(-count); // Return last N runs
259}
260
261/**
262 * Fetches complete agent reference data

Callers 1

fetchAgentReferenceDataFunction · 0.85

Calls 2

getIterationsForAgentMethod · 0.80
getHistoricalSessionsMethod · 0.80

Tested by

no test coverage detected