Skip to main content

Hi! I'm struggling with object handling in Agent Script. Is it possible at all? i've tried using dot notation and bracket notation to populate a key, but to no avail. Can someone offer info or documentation regarding this? Thanks in advance 

 

#Agentforce

2 respostas
  1. 20 de out., 17:09

     Agent Script does NOT support direct dot/bracket notation to write into object variable properties. This is a known limitation.

    Here's what the official docs actually say about 

    object

     type variables:

    What IS supported:

    Agent Script supports these variable types: 

    string

    , 

    boolean

    , 

    number

    , 

    object

    , and 

    list[type]

    . You can declare an 

    object

     variable like this:

    variables:

    CandidateList: mutable list[object] = []

    description: "List of contacts returned from an action"

     

    How objects actually get populated — only via action outputs:

    The only supported way to populate an 

    object

     or 

    list[object]

     variable is by capturing it from an action's output using 

    set

    :

    reasoning:

    instructions: ->

    run @actions.Get_Questions

    with JobScreeningRecordId=@variables.JobRecordID

    set @variables.questions = @outputs.AllScreeningQuestions

     

    You cannot do 

    @variables.myObj.someKey = "value"

     or 

    @variables.myObj["someKey"] = "value"

     — the language has no write syntax for individual object properties.

    What you CAN do with objects after storing them:

    • Read them in LLM prompts: 
    {!@variables.questions[@variables.current_question]}

    Pass the whole object as an action input

    • Use 
    len(@variables.myList)

     on a list of objects

    The workaround:

    If you need to build up a structured object with specific keys, the correct pattern is to:

    1. Use separate primitive variables ( 
    string

    , 

    boolean

    , 

    number

    ) for each field you need to track

    1. Pass those individual variables as inputs to an action that assembles the object server-side (Apex/Flow)
    2. Store the assembled result back via 
    set @variables.result = @outputs.assembledObject

    Docs references: