microsoft / microsoft/TypeChat

Should FunctionCall be part of the Expression?

Open
#124 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
8.7k
Forks
414
Avg merge
3h 8m
Merged PRs (30d)
3

Description

The following schema is introduced in https://github.com/microsoft/TypeChat/pull/20.

// A program consists of a sequence of expressions that are evaluated in order.
export type Program = {
    "@steps": Expression[];
}

// An expression is a JSON value, a function call, or a reference to the result of a preceding expression.
export type Expression = JsonValue | FunctionCall | ResultReference;

// A JSON value is a string, a number, a boolean, null, an object, or an array. Function calls and result
// references can be nested in objects and arrays.
export type JsonValue = string | number | boolean | null | { [x: string]: Expression } | Expression[];

// A function call specifices a function name and a list of argument expressions. Arguments may contain
// nested function calls and result references.
export type FunctionCall = {
    // Name of the function
    "@func": string;
    // Arguments for the function
    "@args": Expression[];
};

// A result reference represents the value of an expression from a preceding step.
export type ResultReference = {
    // Index of the previous expression in the "@steps" array
    "@ref": number;
};

However, I don't think FunctionCall should be part of Expression type. Because { [x: string]: Expression } is part of JsonValue. The output of gpt model is "@steps": Expression[], the execution order is determined. Because when we allow FunctionCall in an object-like value, the execution order is undetermined. Example:

with FunctionCall
{
  "@steps": [
    {
      "@func": "func1",
      "@args": [
        {
          "a": {
            "@func": "func2",
            "args": []
          },
          "b": {
            "@func": "func3",
            "args": []
          }
        }
      ]
    }
  ]
}

we don't know the execution order of func2 vs func3

with Reference
{
  "@steps": [
    {
      "@func": "func3",
      "args": []
    },
    {
      "@func": "func2",
      "args": []
    },
    {
      "@func": "func1",
      "@args": [
        {
          "a": {
            "@ref": 0
          },
          "b": {
            "@ref": 1
          }
        }
      ]
    }
  ]
}

func3 is executed first, then func2.


I'm not sure in what scenarios the gpt model can produce @steps with reference to FunctionCall, in the tests I run, only ResultReference is produced. Is gpt model able to understand the difference between reference to the result of previous functioncall and execute every times it is evaluated?

I think it would be 'safer' to design the generic schema as deterministic as possible. For example, in a financial application, the execution orders matters for the state mutation for user's funds.

therefore, a more strict schema version is:

export type Program = {
    "@steps": FunctionCall[];
}

export type Expression = JsonValue | ResultReference;

export type JsonValue = string | number | boolean | null | { [x: string]: Expression } | Expression[];

export type FunctionCall = {
    "@func": string;
    "@args": Expression[];
};

export type ResultReference = {
    "@ref": number;
};

@ahejlsberg @steveluc does it make sense? Have you seen any example with including FunctionCall in Expression?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the schema introduced in PR #20 and tracing how @steps, FunctionCall, and ResultReference are interpreted. Compare the nested-call and reference examples, then resolve whether evaluation order must be explicit; done means an agreed schema and documented behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
ai
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.