Tool call started event

I want to start playing the background audio when a specific tool call is started (because I know it will take a long time). There is currently no way for this
conversation item added event → only for llm chat response
function call executed event → only after the function call is done

Is there a way to also emit a function call started event or another workaround that is not passing callbacks into my tools?

Hi Kristof, welcome to the new forum :waving_hand:

I swear I have seen this question come up before with a thorough answer, but I can’t find it - that is one benefit of moving to this new platform, previous answers should be easier to find.

Two ideas spring to mind:

    async def llm_node(
        self,
        chat_ctx: llm.ChatContext,
        tools: list[llm.FunctionTool],
        model_settings: ModelSettings,
    ) -> AsyncIterable[llm.ChatChunk | str]:
        """Custom LLM node that detects and logs when the model emits tool calls."""
        async for chunk in Agent.default.llm_node(
            self, chat_ctx, tools, model_settings
        ):
            if isinstance(chunk, llm.ChatChunk) and chunk.delta and chunk.delta.tool_calls:
                for tool in chunk.delta.tool_calls:
                    if getattr(tool, "type", "function") == "function":
                        name = getattr(tool, "name", None)
                        if name:
                            logger.info("Tool call detected: %s", name)
            yield chunk

Yes, indeed this is a workaround. But what I do then is emit the event back to my session, because that is where the other events are thrown to stop the background noise. It seems to me like this is a sensible event to add to the default events of an agentSession?

I added a drawing of what this event currently feels like in my setup.
(in typescript I add the session onto the async local storage and cast it to a default nodeJs event emitter and then push the event to it from my llm node)

There are already handles within the agent_activity agents-js/agents/src/voice/agent_activity.ts at f29d308b4d5f2bfa5c5d9b2e3f645aeb23519930 · livekit/agents-js · GitHub

These should additionally emit the representative events as well