Class: SimpleAcp::Server::Context
- Inherits:
-
Object
- Object
- SimpleAcp::Server::Context
- Defined in:
- lib/simple_acp/server/context.rb
Overview
Request context passed to agent handlers during execution.
Provides access to input messages, session state, conversation history, and methods for controlling execution flow.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#input ⇒ Array<Models::Message>
readonly
Input messages for this run.
-
#run ⇒ Models::Run
readonly
The current run being executed.
-
#server ⇒ Server::Base
readonly
Reference to the server.
-
#session ⇒ Models::Session?
readonly
The session (if any).
Instance Method Summary collapse
-
#agent_name ⇒ String
The name of the agent being executed.
-
#await_message(prompt_message) ⇒ RunYieldAwait
Request additional input from the client, pausing execution.
-
#cancel! ⇒ void
Mark the run as cancelled.
-
#cancelled? ⇒ Boolean
Check if the run has been cancelled.
-
#history ⇒ Array<Models::Message>
Get conversation history from the session.
-
#initialize(run:, session:, input:, server:) ⇒ Context
constructor
Initialize a new context.
-
#log(message) ⇒ void
Log a message for debugging or trajectory tracking.
-
#resume_message ⇒ Models::Message?
Get the resume message (only available during resume).
-
#run_id ⇒ String
The unique run ID.
-
#session_id ⇒ String?
The session ID if a session is active.
-
#set_state(new_state) ⇒ void
Update the session state with new data.
-
#state ⇒ Object?
Get arbitrary state data from the session.
Constructor Details
#initialize(run:, session:, input:, server:) ⇒ Context
Initialize a new context.
41 42 43 44 45 46 47 |
# File 'lib/simple_acp/server/context.rb', line 41 def initialize(run:, session:, input:, server:) @run = run @session = session @input = input @server = server @cancelled = false end |
Instance Attribute Details
#input ⇒ Array<Models::Message> (readonly)
Returns input messages for this run.
30 31 32 |
# File 'lib/simple_acp/server/context.rb', line 30 def input @input end |
#run ⇒ Models::Run (readonly)
Returns the current run being executed.
24 25 26 |
# File 'lib/simple_acp/server/context.rb', line 24 def run @run end |
#server ⇒ Server::Base (readonly)
Returns reference to the server.
33 34 35 |
# File 'lib/simple_acp/server/context.rb', line 33 def server @server end |
#session ⇒ Models::Session? (readonly)
Returns the session (if any).
27 28 29 |
# File 'lib/simple_acp/server/context.rb', line 27 def session @session end |
Instance Method Details
#agent_name ⇒ String
Returns the name of the agent being executed.
50 51 52 |
# File 'lib/simple_acp/server/context.rb', line 50 def agent_name @run.agent_name end |
#await_message(prompt_message) ⇒ RunYieldAwait
Request additional input from the client, pausing execution.
This puts the run into an "awaiting" state until the client calls resume with the requested input.
118 119 120 121 122 123 124 125 |
# File 'lib/simple_acp/server/context.rb', line 118 def () request = Models::MessageAwaitRequest.new(message: ) @run.await!(request) @server.storage.save_run(@run) # Return a result that indicates the run is awaiting RunYieldAwait.new(request: request) end |
#cancel! ⇒ void
This method returns an undefined value.
Mark the run as cancelled.
74 75 76 |
# File 'lib/simple_acp/server/context.rb', line 74 def cancel! @cancelled = true end |
#cancelled? ⇒ Boolean
Check if the run has been cancelled.
67 68 69 |
# File 'lib/simple_acp/server/context.rb', line 67 def cancelled? @cancelled end |
#history ⇒ Array<Models::Message>
Get conversation history from the session.
81 82 83 |
# File 'lib/simple_acp/server/context.rb', line 81 def history @session&.history || [] end |
#log(message) ⇒ void
This method returns an undefined value.
Log a message for debugging or trajectory tracking.
131 132 133 |
# File 'lib/simple_acp/server/context.rb', line 131 def log() SimpleAcp.logger&.info("[#{agent_name}] #{}") end |
#resume_message ⇒ Models::Message?
Get the resume message (only available during resume).
This method returns nil for initial contexts. Override in ResumeContext to return the actual resume message.
141 142 143 |
# File 'lib/simple_acp/server/context.rb', line 141 def nil end |
#run_id ⇒ String
Returns the unique run ID.
55 56 57 |
# File 'lib/simple_acp/server/context.rb', line 55 def run_id @run.run_id end |
#session_id ⇒ String?
Returns the session ID if a session is active.
60 61 62 |
# File 'lib/simple_acp/server/context.rb', line 60 def session_id @session&.id end |
#set_state(new_state) ⇒ void
This method returns an undefined value.
Update the session state with new data.
96 97 98 99 |
# File 'lib/simple_acp/server/context.rb', line 96 def set_state(new_state) @session&.set_state(new_state) @server.storage.save_session(@session) if @session end |
#state ⇒ Object?
Get arbitrary state data from the session.
88 89 90 |
# File 'lib/simple_acp/server/context.rb', line 88 def state @session&.state end |