Skip to content

builtin_handlers

Class info

Classes

Name Children Inherits
FileEditProgressEvent
llmling_agent.agent.events
Event for file edit progress with diff information.
    ProcessExitEvent
    llmling_agent.agent.events
    Event for process completion.
      ProcessStartEvent
      llmling_agent.agent.events
      Event for process start operations.
        RunErrorEvent
        llmling_agent.agent.events
        Signals an error during an agent run.
          StreamCompleteEvent
          llmling_agent.agent.events
          Event indicating streaming is complete with final message.
            ToolCallStartEvent
            llmling_agent.agent.events
            Event indicating a tool call has started with rich ACP metadata.

              🛈 DocStrings

              Built-in event handlers for simple console output.

              detailed_print_handler async

              detailed_print_handler(ctx: RunContext, event: RichAgentStreamEvent[Any]) -> None
              

              Detailed event handler with rich tool execution information.

              Focus: Comprehensive execution visibility. Prints: - Text content (streaming) - Thinking content - Tool calls with inputs - Tool results - Process execution - File operations - Errors

              Source code in src/llmling_agent/agent/builtin_handlers.py
               72
               73
               74
               75
               76
               77
               78
               79
               80
               81
               82
               83
               84
               85
               86
               87
               88
               89
               90
               91
               92
               93
               94
               95
               96
               97
               98
               99
              100
              101
              102
              103
              104
              105
              106
              107
              108
              109
              110
              111
              112
              113
              114
              115
              116
              117
              118
              119
              120
              121
              122
              123
              124
              125
              126
              127
              128
              129
              130
              131
              132
              133
              async def detailed_print_handler(ctx: RunContext, event: RichAgentStreamEvent[Any]) -> None:
                  """Detailed event handler with rich tool execution information.
              
                  Focus: Comprehensive execution visibility.
                  Prints:
                  - Text content (streaming)
                  - Thinking content
                  - Tool calls with inputs
                  - Tool results
                  - Process execution
                  - File operations
                  - Errors
                  """
                  match event:
                      case (
                          PartStartEvent(part=TextPart(content=delta))
                          | PartDeltaEvent(delta=TextPartDelta(content_delta=delta))
                      ):
                          print(delta, end="", flush=True)
              
                      case (
                          PartStartEvent(part=ThinkingPart(content=delta))
                          | PartDeltaEvent(delta=ThinkingPartDelta(content_delta=delta))
                      ):
                          if delta:
                              print(f"\n💭 {delta}", end="", flush=True)
              
                      case ToolCallStartEvent(tool_name=tool_name, title=title, tool_call_id=call_id):
                          print(f"\n🔧 {tool_name}: {title} (#{call_id[:8]})", flush=True)
              
                      case FunctionToolCallEvent(part=ToolCallPart(tool_name=tool_name, args=args)):
                          args_str = str(args)
                          if len(args_str) > 100:  # noqa: PLR2004
                              args_str = args_str[:97] + "..."
                          print(f"  📝 Input: {args_str}", flush=True)
              
                      case FunctionToolResultEvent(result=ToolReturnPart(content=content, tool_name=tool_name)):
                          result_str = str(content)
                          if len(result_str) > 150:  # noqa: PLR2004
                              result_str = result_str[:147] + "..."
                          print(f"  ✅ {tool_name}: {result_str}", flush=True)
              
                      case ProcessStartEvent(process_id=pid, command=command, success=success):
                          if success:
                              print(f"  🖥️  Started process: {command} (PID: {pid})", flush=True)
                          else:
                              print(f"  ❌ Failed to start: {command}", flush=True)
              
                      case ProcessExitEvent(process_id=pid, exit_code=code, success=success):
                          status = "✅" if success else "❌"
                          print(f"  {status} Process {pid} exited: code {code}", flush=True)
              
                      case FileEditProgressEvent(path=path, status=status):
                          emoji = {"in_progress": "✏️", "completed": "✅", "failed": "❌"}.get(status, "📝")
                          print(f"  {emoji} {status}: {path}", flush=True)
              
                      case RunErrorEvent(message=message, code=code):
                          error_info = f" [{code}]" if code else ""
                          print(f"\n❌ Error{error_info}: {message}", flush=True)
              
                      case StreamCompleteEvent():
                          print()  # Final newline
              

              resolve_event_handlers

              resolve_event_handlers(
                  event_handlers: Sequence[IndividualEventHandler | BuiltinEventHandlerType] | None,
              ) -> list[IndividualEventHandler]
              

              Resolve event handlers, converting builtin handler names to actual handlers.

              Source code in src/llmling_agent/agent/builtin_handlers.py
              136
              137
              138
              139
              140
              141
              142
              143
              def resolve_event_handlers(
                  event_handlers: Sequence[IndividualEventHandler | BuiltinEventHandlerType] | None,
              ) -> list[IndividualEventHandler]:
                  """Resolve event handlers, converting builtin handler names to actual handlers."""
                  if not event_handlers:
                      return []
                  builtin_map = {"simple": simple_print_handler, "detailed": detailed_print_handler}
                  return [builtin_map[h] if isinstance(h, str) else h for h in event_handlers]
              

              simple_print_handler async

              simple_print_handler(ctx: RunContext, event: AgentStreamEvent) -> None
              

              Simple event handler that prints text and basic tool information.

              Focus: Core text output and minimal tool notifications. Prints: - Text content (streaming) - Tool calls (name only) - Errors

              Source code in src/llmling_agent/agent/builtin_handlers.py
              43
              44
              45
              46
              47
              48
              49
              50
              51
              52
              53
              54
              55
              56
              57
              58
              59
              60
              61
              62
              63
              64
              65
              66
              67
              68
              69
              async def simple_print_handler(ctx: RunContext, event: AgentStreamEvent) -> None:
                  """Simple event handler that prints text and basic tool information.
              
                  Focus: Core text output and minimal tool notifications.
                  Prints:
                  - Text content (streaming)
                  - Tool calls (name only)
                  - Errors
                  """
                  match event:
                      case (
                          PartStartEvent(part=TextPart(content=delta))
                          | PartDeltaEvent(delta=TextPartDelta(content_delta=delta))
                      ):
                          print(delta, end="", flush=True)
              
                      case FunctionToolCallEvent(part=ToolCallPart(tool_name=tool_name)):
                          print(f"\n🔧 {tool_name}", flush=True)
              
                      case FunctionToolResultEvent(result=ToolReturnPart()):
                          pass  # Silent completion
              
                      case RunErrorEvent(message=message):
                          print(f"\n❌ Error: {message}", flush=True)
              
                      case StreamCompleteEvent():
                          print()  # Final newline