module Riffer::Agent::Serializer
Constants
- DEFAULT_TOOL_RESOLVER
- SCHEMA_VERSION
-
Bump only on an incompatible change to the hash shape.
Public Instance Methods
Source
# File lib/riffer/agent/serializer.rb, line 37 def from_h(hash, context: nil, session: nil, tool_resolver: DEFAULT_TOOL_RESOLVER, tool_runtime: nil) # One arm per supported version keeps older hashes decodable after a breaking change. case hash[:schema_version] when SCHEMA_VERSION decode_v1(hash, context: context, session: session, tool_resolver: tool_resolver, tool_runtime: tool_runtime) else raise VersionError, "Unsupported schema_version: #{hash[:schema_version].inspect} (this Riffer supports #{SCHEMA_VERSION})" end end
Raises Riffer::Agent::Serializer::VersionError on an unsupported schema_version.
Source
# File lib/riffer/agent/serializer.rb, line 56 def from_json(json, context: nil, session: nil, tool_resolver: DEFAULT_TOOL_RESOLVER, tool_runtime: nil) from_h( JSON.parse(json, symbolize_names: true), context: context, session: session, tool_resolver: tool_resolver, tool_runtime: tool_runtime, ) end
Source
# File lib/riffer/agent/serializer.rb, line 18 def to_h(agent:) # Already resolved against the agent's context, so the hash carries plain data, never Procs. config = agent.config { schema_version: SCHEMA_VERSION, riffer_version: Riffer::VERSION, identifier: config.identifier, model: "#{agent.provider_name}/#{agent.model_name}", instructions: agent.instruction_message&.content, model_options: config.model_options, max_steps: encode_max_steps(config.max_steps), structured_output: config.structured_output&.to_json_schema(strict: false), tools: agent.tools.map { |tool_class| tool_descriptor(tool_class) }, } end
Source
# File lib/riffer/agent/serializer.rb, line 50 def to_json(agent:) JSON.generate(to_h(agent: agent)) end