Class: Keycardai::A2A::DelegationClient
- Inherits:
-
Object
- Object
- Keycardai::A2A::DelegationClient
- Defined in:
- lib/keycardai/a2a/delegation_client.rb
Overview
Calls another agent on the user's behalf, carrying the user's identity through the hop: discover the target's agent card, exchange the inbound user token for one scoped to the target (RFC 8693; the user stays the subject and the authorization server records this agent in the act chain), and invoke the target's JSON-RPC endpoint with the exchanged token as the bearer credential.
Instance Method Summary collapse
-
#initialize(issuer:, credential: nil, client_id: nil, client_secret: nil, http_client: OAuth::HTTP::NetHTTPClient.new, discovery: nil, invoke_timeout: nil, protocol_version: PROTOCOL_VERSION) ⇒ DelegationClient
constructor
A new instance of DelegationClient.
-
#invoke(target:, subject_token:, message:) ⇒ Result
Delegate a call to another agent: discover, exchange, invoke.
Constructor Details
#initialize(issuer:, credential: nil, client_id: nil, client_secret: nil, http_client: OAuth::HTTP::NetHTTPClient.new, discovery: nil, invoke_timeout: nil, protocol_version: PROTOCOL_VERSION) ⇒ DelegationClient
Returns a new instance of DelegationClient.
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/keycardai/a2a/delegation_client.rb', line 28 def initialize(issuer:, credential: nil, client_id: nil, client_secret: nil, http_client: OAuth::HTTP::NetHTTPClient.new, discovery: nil, invoke_timeout: nil, protocol_version: PROTOCOL_VERSION) @exchange = OAuth::TokenExchangeClient.new(issuer: issuer, credential: credential, client_id: client_id, client_secret: client_secret, http_client: http_client) @discovery = discovery || ServiceDiscovery.new(http_client: http_client) @http_client = http_client @invoke_timeout = invoke_timeout @protocol_version = protocol_version end |
Instance Method Details
#invoke(target:, subject_token:, message:) ⇒ Result
Delegate a call to another agent: discover, exchange, invoke.
49 50 51 52 53 54 |
# File 'lib/keycardai/a2a/delegation_client.rb', line 49 def invoke(target:, subject_token:, message:) card = @discovery.get_card(target) token = @exchange.exchange_token(subject_token: subject_token, resource: target.chomp("/")) result = post_jsonrpc(jsonrpc_url(target, card), token.access_token, ) Result.new(message: result, agent_card: card) end |