Skip to content

CallbackRouter

Base classes

Name Children Inherits
AgentRouter
llmling_agent.delegation.router
Base class for routing messages between agents.
Generic
typing
Abstract base class for generic types.

⋔ Inheritance diagram

graph TD
  94350422104288["router.CallbackRouter"]
  94350422103296["router.AgentRouter"]
  140709601677504["builtins.object"]
  94350360566400["typing.Generic"]
  94350422103296 --> 94350422104288
  140709601677504 --> 94350422103296
  94350360566400 --> 94350422104288
  140709601677504 --> 94350360566400

🛈 DocStrings

Bases: AgentRouter

Router using callback function for decisions.

Source code in src/llmling_agent/delegation/router.py
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
class CallbackRouter[TMessage](AgentRouter):
    """Router using callback function for decisions."""

    def __init__(
        self,
        pool: AgentPool,
        decision_callback: DecisionCallback[TMessage],
    ):
        self.pool = pool
        self.decision_callback = decision_callback

    async def decide(self, message: TMessage) -> Decision:
        """Execute callback and handle sync/async appropriately."""
        result = self.decision_callback(message, self.pool, self)
        if inspect.isawaitable(result):
            return await result
        return result

decide async

decide(message: TMessage) -> Decision

Execute callback and handle sync/async appropriately.

Source code in src/llmling_agent/delegation/router.py
139
140
141
142
143
144
async def decide(self, message: TMessage) -> Decision:
    """Execute callback and handle sync/async appropriately."""
    result = self.decision_callback(message, self.pool, self)
    if inspect.isawaitable(result):
        return await result
    return result

Show source on GitHub