Skip to main content

Module tower_service

Module tower_service 

Source
Expand description

§Tower Service Integration

Bridges Bob’s port traits with the tower::Service ecosystem, enabling composition with standard middleware (timeout, retry, rate limit, etc.) without reimplementing them in the framework.

§Design Philosophy

This module demonstrates extreme trait reuse by leveraging tower::Service as the universal middleware abstraction instead of building custom middleware chains.

§Key Patterns

  • Blanket implementations: Every ToolPort automatically becomes a tower::Service
  • Extension traits: Fluent APIs for middleware composition
  • Type-state builders: Compile-time validation of middleware chains
  • Associated types: Bind request/response types to service definitions

§Example

use bob_runtime::tower_service::*;
use tower::ServiceBuilder;
use std::time::Duration;

// Wrap a ToolPort with tower middleware
let tool_service = ToolService::new(my_tool_port);
let guarded = ServiceBuilder::new()
    .timeout(Duration::from_secs(15))
    .rate_limit(10, Duration::from_secs(1))
    .service(tool_service);

Structs§

LlmRequestWrapper
Request type for LLM completion services.
LlmResponseWrapper
Response type for LLM completion services.
LlmService
A tower::Service wrapper around LlmPort::complete.
ToolListRequest
Request type for tool listing services.
ToolListService
A tower::Service wrapper around ToolPort::list_tools.
ToolRequest
Request type for tool execution services.
ToolResponse
Response type for tool execution services.
ToolService
A tower::Service wrapper around ToolPort::call_tool.

Traits§

LlmPortServiceExt
Extension trait that converts an LlmPort into a tower service.
ServiceExt
Extension trait for ergonomic service composition.
ToolPortServiceExt
Extension trait that converts a ToolPort into tower services.