MCPcopy Index your code
hub / github.com/google/adk-python / CountInvocationPlugin

Class CountInvocationPlugin

contributing/samples/core/app/agent.py:28–49  ·  view source on GitHub ↗

A custom plugin that counts agent and LLM invocations.

Source from the content-addressed store, hash-verified

26
27
28class CountInvocationPlugin(BasePlugin):
29 """A custom plugin that counts agent and LLM invocations."""
30
31 def __init__(self) -> None:
32 """Initialize the plugin with counters."""
33 super().__init__(name="count_invocation")
34 self.agent_count: int = 0
35 self.llm_request_count: int = 0
36
37 async def before_agent_callback(
38 self, *, agent: BaseAgent, callback_context: CallbackContext
39 ) -> None:
40 """Count agent runs."""
41 self.agent_count += 1
42 print(f"[Plugin] Agent run count: {self.agent_count}")
43
44 async def before_model_callback(
45 self, *, callback_context: CallbackContext, llm_request: LlmRequest
46 ) -> None:
47 """Count LLM requests."""
48 self.llm_request_count += 1
49 print(f"[Plugin] LLM request count: {self.llm_request_count}")
50
51
52root_agent = Agent(

Callers 1

agent.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected