-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Cerebras support. Add initial Slackbot code. Add agent execution …
…completion handlers
- Loading branch information
1 parent
9361119
commit 004fade
Showing
101 changed files
with
952 additions
and
522 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,62 @@ | ||
import { AgentCompleted, AgentContext } from '#agent/agentContextTypes'; | ||
import { FunctionCallResult } from '#llm/llm'; | ||
import { logger } from '#o11y/logger'; | ||
import { envVar } from '#utils/env-var'; | ||
|
||
/** | ||
* Runs the completionHandler on an agent | ||
* @param agent | ||
*/ | ||
export async function runAgentCompleteHandler(agent: AgentContext): Promise<void> { | ||
try { | ||
const completionHandler = agent.completedHandler ?? new ConsoleCompletedHandler(); | ||
await completionHandler.notifyCompleted(agent); | ||
} catch (e) { | ||
logger.warn(e, `Completion handler error for agent ${agent.agentId}`); | ||
throw e; | ||
} | ||
} | ||
|
||
/** | ||
* Creates a generic notification message for the completion of an agent execution | ||
* @param agent | ||
*/ | ||
export function completedNotificationMessage(agent: AgentContext) { | ||
const uiUrl = envVar('UI_URL'); | ||
let message = stateNotificationMessage(agent); | ||
message += `\n${uiUrl}/agent/${agent.agentId}`; | ||
return message; | ||
} | ||
|
||
/** | ||
* Outputs the standard agent completion message to the console | ||
*/ | ||
export class ConsoleCompletedHandler implements AgentCompleted { | ||
notifyCompleted(agentContext: AgentContext): Promise<void> { | ||
console.log(completedNotificationMessage(agentContext)); | ||
return Promise.resolve(); | ||
} | ||
|
||
agentCompletedHandlerId(): string { | ||
return 'console'; | ||
} | ||
} | ||
|
||
export function stateNotificationMessage(agent: AgentContext): string { | ||
switch (agent.state) { | ||
case 'error': | ||
return `Agent error.\nName:${agent.name}\nError: ${agent.error}`; | ||
case 'hil': | ||
return `Agent has reached Human-in-the-loop threshold.\nName: ${agent.name}`; | ||
case 'feedback': | ||
return `Agent has requested feedback.\nName: ${agent.name}\n:Question: ${getLastFunctionCallArg(agent)}`; | ||
case 'completed': | ||
return `Agent has completed.\nName: ${agent.name}\nNote: ${getLastFunctionCallArg(agent)}`; | ||
default: | ||
} | ||
} | ||
|
||
export function getLastFunctionCallArg(agent: AgentContext) { | ||
const result: FunctionCallResult = agent.functionCallHistory.slice(-1)[0]; | ||
return Object.values(result.parameters)[0]; | ||
} |
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
Oops, something went wrong.