Module: Parse::Agent::FieldNames

Defined in:
lib/parse/agent/field_names.rb

Overview

Per-agent data-field naming mode for tool output.

Parse::Agent.new(field_names: :server) asks for data fields in the exact names Parse returns or the model declares through its field_map (createdAt, totalPlays, ExternalID), with no snake_case conversion anywhere a tool would otherwise apply one. :default (or omitting the option) keeps every tool's existing output.

Only data-field keys are affected. MCP protocol keys and SDK envelope keys (chunks, documents, object_id, next_call, ...) keep their contracts, and "server names" never means raw MongoDB storage columns (_p_author, _rperm, _session_token). Naming is presentation only: every access check (ACL/CLP, protectedFields, class and per-agent field policies) resolves against canonical field identities before output.

Like FieldPolicy, the mode is scoped fiber-locally around each tool call by Tools.invoke, so concurrent agents with different modes never see each other's setting and nothing global is mutated.

Constant Summary collapse

SCOPE_KEY =
:parse_agent_field_names_scope

Class Method Summary collapse

Class Method Details

.current_mode ⇒ Symbol

Returns :server or :default for the agent whose tool is executing; :default outside a tool call.

Returns:

  • (Symbol) —

    :server or :default for the agent whose tool is executing; :default outside a tool call.



41
42
43
44
45
# File 'lib/parse/agent/field_names.rb', line 41

def current_mode
  agent = Fiber[SCOPE_KEY]
  mode = agent.respond_to?(:field_names_mode) ? agent.field_names_mode : nil
  mode || :default
end

.server? ⇒ Boolean

Returns true when the executing agent asked for server names.

Returns:

  • (Boolean) —

    true when the executing agent asked for server names.



48
49
50
# File 'lib/parse/agent/field_names.rb', line 48

def server?
  current_mode == :server
end

.with(agent) ⇒ Object

Run the block with agent's naming mode in effect.



31
32
33
34
35
36
37
# File 'lib/parse/agent/field_names.rb', line 31

def with(agent)
  previous = Fiber[SCOPE_KEY]
  Fiber[SCOPE_KEY] = agent
  yield
ensure
  Fiber[SCOPE_KEY] = previous
end