feat(callbacks): Integrate callback hooks into agent execution flow#118
feat(callbacks): Integrate callback hooks into agent execution flow#118
Conversation
This commit integrates the callback infrastructure (from PR #94) into the actual agent execution flow. Callbacks are now invoked at key execution points: - BeforeAgent/AfterAgent: Hook into overall agent execution lifecycle - BeforeModel/AfterModel: Hook into LLM calls for caching, guardrails, etc. - BeforeTool/AfterTool: Hook into tool execution for authorization, logging, etc. Changes include: - Add WithCallbacks() method to AgentBuilder for fluent callback configuration - Integrate BeforeAgent callback at start of RunWithStream (can skip execution) - Integrate AfterAgent callback at completion (can modify final output) - Integrate BeforeModel callback before LLM calls (can skip and return cached response) - Integrate AfterModel callback after LLM responses (can modify response) - Integrate BeforeTool/AfterTool callbacks around tool execution - Add AgentName field to AgentConfig for callback context - Add helper methods createCallbackContext and createToolContext - Create callbacks example with comprehensive documentation - Regenerate AgentBuilder mock Closes #71 Co-authored-by: Eden Reich <edenreich@users.noreply.github.com>
|
@claude Fix the CI. Please also remove all the self-explanatory functions body inline comments. |
|
Claude finished @edenreich's task —— View job Fixing CI and Removing Self-Explanatory Comments
Summary: Fixed CI failures and cleaned up the code:
Commit: | |
- Fix markdown table alignment in README.md (prettier formatting) - Add blank lines before code blocks/lists per prettier style - Fix struct field alignment in agent_builder.go (gofmt) - Remove redundant inline comments from agent_streamable.go - Remove section comments from callbacks example main.go Co-authored-by: Eden Reich <edenreich@users.noreply.github.com>
|
@claude CI is still failing - fix it. |
|
Claude finished @edenreich's task —— View job Fixing CI Failures
Summary: Fixed the CI "Check dirty" failure by adding the required blank lines before bullet lists in |
🤖 Generated with [Claude Code](https://claude.ai/claude-code) Co-authored-by: Eden Reich <edenreich@users.noreply.github.com>
Joshswooft
left a comment
There was a problem hiding this comment.
It looks like the AI has followed the implementation of how the callbacks have been designed to work i.e. skipping the calls or using the overidded values. What I'm not certain about is the surrounding logic in the RunWithStream and if it has correctly followed it.
I think overall if this PR goes in a refactor of this function is probably going to be required otherwise it's far too messy to work with.
|
@edenreich No serious change requests from my side 👍 |
Awesome! thanks for taking the time to look at it - I'll make those adjustments and merge it. |
|
@claude Can you go over the comments to addresse those issues and prepare the PR for a final review? I want to merge this. |
|
Claude finished @edenreich's task —— View job Addressing Review Comments for Final ReviewAll review comments have been addressed and changes are committed:
SummarySuccessfully addressed both review comments from @Joshswooft:
All changes have been tested:
Commit: The PR is now ready for final review and merge! 🚀 | |
- Remove repetitive "Use Cases" section from callbacks README - Add GetTool method to ToolBox interface for cleaner tool access - Simplify agent_streamable.go to use new GetTool method - Regenerate mocks for updated interface 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Eden Reich <edenreich@users.noreply.github.com>
Signed-off-by: Eden Reich <eden.reich@gmail.com>
|
Ok tested in the example and it looks good to me: |
|
🎉 This PR is included in version 0.16.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
This PR integrates the callback infrastructure (from PR #94) into the actual agent execution flow.
Changes
WithCallbacks()method to AgentBuilderCloses #71
🤖 Generated with Claude Code