Skip to content

Expose agent lifecycle hooks (on_usage, on_retry, on_provider_fallback, on_compact_*) through Config and CodeLoop public API #29

Description

@FernandoCelmer

Problem

Agent has a rich set of lifecycle callbacks — on_usage, on_retry, on_provider_fallback, on_compact_start, on_compact_end, on_trace_event, on_request, on_turn_end — that are useful for monitoring, logging, and building custom UIs. However, none of these are exposed through Config or CodeLoop. Library users who want to hook into these events must reach into flow.CodeLoop.agent directly (bypassing the public API) or subclass Agent.

flow = CodeLoop(config=Config(...))
flow.agent.on_usage = my_callback    # private, undocumented

The VS Code extension and any third-party integrations that embed CodeLoop as a library have no stable hook surface.

Steps to reproduce / context

A library user wants to display a token counter:

flow = CodeLoop(config=Config(...))
# No public way to register on_usage without touching flow.agent internals

Expected behavior

Config should accept the same lifecycle callbacks as Agent and pass them through. CodeLoop.run() should set them on the agent before each run (in case Config is mutated after construction).

Suggested fix

Add optional callback parameters to Config.__init__() and store them. In CodeLoop.__init__() (or run()), assign them to self.agent.*. Alternatively, expose a CodeLoop.on(event_name, callback) registration method for a cleaner public API. This is additive and non-breaking.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions