Skip to content

feature: Add the callbacks ready to be used by the agent#94

Merged
edenreich merged 5 commits intoinference-gateway:mainfrom
Joshswooft:callback-executor
Oct 10, 2025
Merged

feature: Add the callbacks ready to be used by the agent#94
edenreich merged 5 commits intoinference-gateway:mainfrom
Joshswooft:callback-executor

Conversation

@Joshswooft
Copy link
Copy Markdown
Contributor

@Joshswooft Joshswooft commented Oct 10, 2025

Adds callbacks by following the ADK docs: https://google.github.io/adk-docs/callbacks/

The callbacks are currently not in use by the agent, I will wait until the refactoring of the RunWithStream method is complete before adding. Consider this the initial plumbing done

@Joshswooft Joshswooft changed the title add the callbacks ready to be used by the agent feature: Add the callbacks ready to be used by the agent Oct 10, 2025
@Joshswooft
Copy link
Copy Markdown
Contributor Author

Joshswooft commented Oct 10, 2025

@edenreich any chance to get this in before more conflicts come up?

And then I can work on implementing the logic into the agents RunWithStream method and add some examples on how it all works

@edenreich
Copy link
Copy Markdown
Contributor

edenreich commented Oct 10, 2025

@Joshswooft I think it looks good so far, do you think we can add an example? to demonstrate how does the server code looks like? when the a2a server for example process a request.

Overall looks great, let me know. Otherwise I'm also happy with just merging it as is and I can add it later.

@edenreich
Copy link
Copy Markdown
Contributor

edenreich commented Oct 10, 2025

@Joshswooft BTW, I can see that we have the CallbackExecutor definition but I can't find where we apply those? for example I couldn't find a reference for the usage of BeforeModelCallback in the default background or streaming task handlers. Maybe we should use those also in the default task handlers? I think the RunWithStream should have those callbacks invoked / executed if they are defined?

@Joshswooft
Copy link
Copy Markdown
Contributor Author

@Joshswooft BTW, I can see that we have the CallbackExecutor definition but I can't find where we apply those? for example I couldn't find a reference for the usage of BeforeModelCallback in the default background or streaming task handlers. Maybe we should use those also in the default task handlers? I think the RunWithStream should have those callbacks invoked / executed if they are defined?

"The callbacks are currently not in use by the agent, " - That will explain why you can't see them. It's going to be a pretty meaty PR if I add this all at once and chances are it's going to fall behind again as I'm away very soon for a few weeks. Adding the prep work in now lets others contribute or delegate to Claude etc.

@Joshswooft
Copy link
Copy Markdown
Contributor Author

Joshswooft commented Oct 10, 2025

@Joshswooft I think it looks good so far, do you think we can add an example? to demonstrate how does the server code looks like? when the a2a server for example process a request.

Overall looks great, let me know. Otherwise I'm also happy with just merging it as is and I can add it later.

I'll add the example once it's hooked up to the agent. It can be a seperate PR

@edenreich
Copy link
Copy Markdown
Contributor

Sounds good!

Copy link
Copy Markdown
Contributor

@edenreich edenreich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@Joshswooft Joshswooft requested a review from edenreich October 10, 2025 19:44
@edenreich edenreich merged commit 84632f3 into inference-gateway:main Oct 10, 2025
1 check passed
@Joshswooft Joshswooft deleted the callback-executor branch October 10, 2025 19:46
ig-semantic-release-bot bot added a commit that referenced this pull request Oct 11, 2025
## [0.14.0](v0.13.1...v0.14.0) (2025-10-11)

### ✨ Features

* Add the callbacks ready to be used by the agent ([#94](#94)) ([84632f3](84632f3))
* **types:** Refactor Part deserialization to use concrete types ([#104](#104)) ([22d192e](22d192e)), closes [#102](#102)

### ♻️ Improvements

* Consolidate the logic of the agent and remove redundancy ([#93](#93)) ([54e5e71](54e5e71))
* **docker-compose:** Remove port mappings for server service to avoid confusion ([3df7b08](3df7b08))
* **server:** Remove handler duplication between A2AServerImpl and DefaultA2AProtocolHandler ([#101](#101)) ([75b9c20](75b9c20))

### 🐛 Bug Fixes

* Improve validation logic for task handler configuration ([#98](#98)) ([34d6354](34d6354))

### 👷 CI

* Add Prettier setup and formatting steps for Go and markdown files ([#105](#105)) ([f2a1994](f2a1994))

### 📚 Documentation

* **examples:** Add input-required flow examples ([#96](#96)) ([17764f3](17764f3))

### 🔧 Miscellaneous

* **deps:** Update claude-code to 2.0.8 and install gh cli version 2.81.0 in flox environment ([4d6e41a](4d6e41a))
@ig-semantic-release-bot
Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.14.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

claude bot added a commit that referenced this pull request Nov 22, 2025
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>
edenreich added a commit that referenced this pull request Dec 3, 2025
…118)

* feat(callbacks): Integrate callback hooks into agent execution flow

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>

* fix(callbacks): Fix formatting and remove self-explanatory comments

- 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>

* fix(callbacks): Add blank lines before lists per prettier formatting

🤖 Generated with [Claude Code](https://claude.ai/claude-code)

Co-authored-by: Eden Reich <edenreich@users.noreply.github.com>

* refactor(callbacks): Address review comments

- 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>

* docs: Document callback system and update examples

* docs: Simplify the example to support docker-compose

Signed-off-by: Eden Reich <eden.reich@gmail.com>

---------

Signed-off-by: Eden Reich <eden.reich@gmail.com>
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Co-authored-by: Eden Reich <edenreich@users.noreply.github.com>
ig-semantic-release-bot bot added a commit that referenced this pull request Dec 3, 2025
## [0.16.0](v0.15.3...v0.16.0) (2025-12-03)

### ✨ Features

* **callbacks:** Integrate callback hooks into agent execution flow ([#118](#118)) ([b69b34b](b69b34b)), closes [#94](#94) [#71](#71)

### 🔧 Miscellaneous

* Add infer agent ([0963b3e](0963b3e))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants