Nous.ToolCall (nous v0.17.0)
View SourceField access for tool-call maps whose keys may be atoms or strings.
Providers return tool calls with string keys (%{"name" => ...}) while the
internal format uses atom keys (%{name: ...}). These helpers resolve a
field across both key styles in one place.
Unlike the call[:name] || call["name"] idiom, field/3 preserves
legitimately-falsy values: arguments: false / 0 / "" are returned
as-is instead of being coalesced into the fallback. Only a missing key or
an explicit nil falls through to the next key style and then the default.
Summary
Functions
Get key from a tool-call map, checking the atom key then its string form.
Put value under key, preserving the map's existing key style.
Functions
Get key from a tool-call map, checking the atom key then its string form.
Returns default when the field is absent or nil under both key styles.
Examples
iex> Nous.ToolCall.field(%{"name" => "search"}, :name)
"search"
iex> Nous.ToolCall.field(%{arguments: false}, :arguments)
false
iex> Nous.ToolCall.field(%{}, :arguments, %{})
%{}
Put value under key, preserving the map's existing key style.
Writes to the atom key when present, otherwise to the existing string key, and defaults to the string form when the field is new (matching the wire format providers use).