Class: AgentHarness::TextTransport
- Inherits:
-
Object
- Object
- AgentHarness::TextTransport
- Defined in:
- lib/agent_harness/text_transport.rb
Overview
Direct HTTP transport for text-only provider interactions.
Bypasses the CLI entirely by calling the provider’s REST API directly. Currently supports Anthropic’s Messages API. This transport is used when callers declare a task as text-only via mode: :text on send_message.
The transport preserves the same Response structure, token tracking, and error classification semantics as the CLI path so that callers do not need to distinguish between transport modes after the call.
Constant Summary collapse
- ANTHROPIC_API_URL =
"https://api.anthropic.com/v1/messages"- ANTHROPIC_API_VERSION =
"2023-06-01"- DEFAULT_MODEL =
"claude-sonnet-4-20250514"- DEFAULT_MAX_TOKENS =
4096- DEFAULT_TIMEOUT =
300
Instance Method Summary collapse
-
#initialize(api_key:, logger: nil) ⇒ TextTransport
constructor
A new instance of TextTransport.
-
#send_message(prompt, model: nil, timeout: nil, max_tokens: nil) ⇒ Response
Send a text-only message via the Anthropic Messages API.
Constructor Details
#initialize(api_key:, logger: nil) ⇒ TextTransport
Returns a new instance of TextTransport.
30 31 32 33 |
# File 'lib/agent_harness/text_transport.rb', line 30 def initialize(api_key:, logger: nil) @api_key = api_key @logger = logger end |
Instance Method Details
#send_message(prompt, model: nil, timeout: nil, max_tokens: nil) ⇒ Response
Send a text-only message via the Anthropic Messages API.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/agent_harness/text_transport.rb', line 46 def (prompt, model: nil, timeout: nil, max_tokens: nil) model ||= DEFAULT_MODEL timeout ||= DEFAULT_TIMEOUT max_tokens ||= DEFAULT_MAX_TOKENS uri = URI(ANTHROPIC_API_URL) body = { model: model, max_tokens: max_tokens, messages: [{role: "user", content: prompt}] } start_time = Time.now http_response = make_request(uri, body, timeout: timeout) duration = Time.now - start_time parse_response(http_response, duration: duration, model: model) end |