Skip to content

Conversation

bradleygolden
Copy link
Contributor

@bradleygolden bradleygolden commented Jul 22, 2025

Adds the on_tool_start and on_tool_end callbacks to setup_ash_ai/2. I initially planned on only adding on_tool_start but decided to also add on_tool_end for consistency. on_tool_response_created is available via langchain but it's a recent addition and not well documented.

Fixes #91.

Contributor checklist

Leave anything that you believe does not apply unchecked.

  • I accept the AI Policy, or AI was not used in the creation of this PR.
  • Bug fixes include regression tests
  • Chores
  • Documentation changes
  • Features include unit/acceptance tests
  • Refactoring
  • Update dependencies

@bradleygolden bradleygolden marked this pull request as ready for review July 22, 2025 13:28
lib/ash_ai.ex Outdated
@@ -243,10 +315,14 @@ defmodule AshAi do
lang_chain
|> LLMChain.add_tools(tools)
|> then(fn llm_chain ->
if opts.actor do
if opts.actor || opts.on_tool_start || opts.on_tool_end do
Copy link
Contributor

Choose a reason for hiding this comment

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

lets just remove this conditional. Looking at it, it already has a bug where it only sets the tenant if the actor is present 😓

Copy link
Contributor

Choose a reason for hiding this comment

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

we can just always set this context.

Remove conditional to prevent bug where tenant isn't set if actor is
`nil`. Instead, always pass opts to custom context.
@bradleygolden bradleygolden requested a review from zachdaniel July 22, 2025 14:52
@zachdaniel zachdaniel merged commit 21c14aa into ash-project:main Jul 22, 2025
22 checks passed
@zachdaniel
Copy link
Contributor

🚀 Thank you for your contribution! 🚀

@bradleygolden bradleygolden deleted the fix-extract-tool-parameter-defaults branch July 22, 2025 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add tool start hook
2 participants