Skip to content

API to manage debugging info (steps, full request/responses) #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
apostolisCodpal opened this issue May 9, 2025 · 8 comments
Open
Milestone

Comments

@apostolisCodpal
Copy link
Contributor

"convex": "^1.23.0"
"@convex-dev/agent": "0.0.15-alpha.2"

This is not urgent, but would become a problem over time.
I couldn't find an API for deleting the steps in the steps table.
Calling components.agent.messages.deleteAllForThreadIdAsync or the Sync version deletes all messages and embeddings. It makes sense to have the steps separately but there should still be an API to delete them. Perhaps by deleted threads.

@ianmacartney
Copy link
Contributor

Agreed! I actually think we should get rid of steps, so long as there's sufficient data available on the messages table. I'm not sure if there are any remaining fields of value.

I avoided surfacing a way to get the steps or manage them b/c I wanted them to be an implementation detail I could change. But not deleting the steps when deleting the thread is a bug, and exposing vacuuming steps would be nice since they're somewhat heavy-weight.

Do you get anything special out of steps? Any objection to phasing them out?

@apostolisCodpal
Copy link
Contributor Author

Steps show the real conversation thread sent to the model, together will exact tool specs etc. It is helping me tremendously for investigation purposes. I don't think I would ever have a need for it other than for investigations though.

@ianmacartney
Copy link
Contributor

ianmacartney commented May 11, 2025 via email

@apostolisCodpal
Copy link
Contributor Author

Those are great suggestions. Database might be easier for a "quick" lookup but logs are lighter and we have integrations that can stream them outside of convex so that direction might make more sense.

LLMs can be quite unpredictable at times as-it-is. Having the ability to log/dump the real JSON and know that you see what they see is crucial to understanding seemingly "unexpected" behaviour.

@ianmacartney ianmacartney changed the title API to delete steps API to manage debugging info (steps, full request/responses) May 13, 2025
@ianmacartney
Copy link
Contributor

ianmacartney commented May 13, 2025

I just had a thought that puts a bit more work on the user, but gives more control over the behavior without the library needing to be overly opinionated / configurable:

const agent = new Agent(components.agent, {
  ...
  onLLMResponse: async (ctx, { request, response, agentName, userId, threadId, ...? }) => {
    // log it in your preferred format to introspect yourself
    console.log({ request, response });
    // and/or dump to a table conditionally
    if (process.env.CAPTURE_RAW_REQUESTS) {
      await ctx.db.insert("rawRequests", { request, response });
    }
  }
});

Not sure about the naming for onLLMResponse.. open to suggestions

@apostolisCodpal
Copy link
Contributor Author

That's a great thought @ianmacartney.
Exposing hooks like that is far more powerful than exposing configuration.
The name is good. The only other name I think of is onAfterGenerate.

If you are doing with this direction I would urge to include also onBeforeGenerate or onBeforeLLMResponse to allow the user to process the request before sending it to the provider.
What I would specifically like to achieve with this (maybe it fits better somewhere else) is the ability to strip text from messages, or messages as a whole, before they are sent to the LLM.

@ianmacartney
Copy link
Contributor

Pre-processing messages is possible at the start of the {generate,stream}{Text,Object} calls, but if you provide maxSteps then we currently only have as much control as the AI SDK exposes - and they don't currently have a callback per-step that modifies the in-progress messages.
However, it sounds like you'd be happy with a callback that did common filtering of the context messages at the very start (or messages in general), maybe even as a parameter in contextOptions. Each subsequent step would have the new messages and not per-step adjustments, however.
wdyt?

@ianmacartney ianmacartney added this to the 2 milestone May 14, 2025
@apostolisCodpal
Copy link
Contributor Author

I need to work with it a bit more to formulate a stronger opinion. Let's leave this for now, if I see any limitations that can be resolved I'll open a separate ticket.

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

No branches or pull requests

2 participants