diff --git a/src/pdl/pdl_interpreter.py b/src/pdl/pdl_interpreter.py index f6bacc23b..58814ca98 100644 --- a/src/pdl/pdl_interpreter.py +++ b/src/pdl/pdl_interpreter.py @@ -577,18 +577,18 @@ def process_block_body( scope, loc, ) - d = { + message = { "role": state.role, "content": content, "defsite": block.pdl__id, } if block.name is not None: name, block = process_expr_of(block, "name", scope, loc) - d["name"] = name + message["name"] = name if block.tool_call_id is not None: tool_call_id, block = process_expr_of(block, "tool_call_id", scope, loc) - d["tool_call_id"] = tool_call_id - result = PdlDict(d) + message["tool_call_id"] = tool_call_id + result = PdlDict(message) background = PdlList([result]) case IfBlock(): b, if_trace = process_condition_of(block, "condition", scope, loc, "if") diff --git a/tests/test_messages.py b/tests/test_messages.py index b02badf82..993ed9fd5 100644 --- a/tests/test_messages.py +++ b/tests/test_messages.py @@ -106,3 +106,34 @@ def test_message4(): "defsite": "message", }, ] + + +def test_messages5(): + prog_str = """ +description: Messages block +array: + - role: tool + content: 42 + name: f + tool_call_id: id +""" + result = exec_str(prog_str, output="all") + context = result["scope"]["pdl_context"] + assert result["result"] == [ + { + "role": "tool", + "content": 42, + "name": "f", + "tool_call_id": "id", + "defsite": "array.0.message", + }, + ] + assert context == [ + { + "role": "tool", + "content": 42, + "name": "f", + "tool_call_id": "id", + "defsite": "array.0.message", + } + ]