Generative AI for Genealogy – Part X

Code Tool Calling

Some of the principles differ with this route. The main concept is beautifully simple:

You ask X → it responds with Y → using a function/method.

Here’s an example:

User: Who is Dave’s mother?

Response:
```csharp
public static string answer()
{ 
  string nameOfMother = AIToolFunctions.GetMother("Dave")

  return $"Dave's mother is {nameOfMother}";
}
```

If you’re reading my blog, I’m assuming you code.

If you don’t, don’t panic — this one is easy to follow:

  • The LLM is told to generate a method called answer().
  • Inside that method, it calls a tool: GetMother("Dave").
  • That tool returns the name of Dave’s mother.
  • The method returns a nice, friendly sentence.

The magic is that the LLM knows to substitute “Dave” into the tool call. It’s not guessing — it’s following the rules we gave it.

In the prompt, we tell the LLM which tools it is allowed to use:

You can use C# code to execute the following tools:
AIToolFunctions.GetMother(name_or_id)
AIToolFunctions.GetFather(name_or_id)
AIToolFunctions.GetChildrenNames(name_or_id)
...

We can even give it step‑by‑step instructions and watch it try to generalise from them — like a toddler learning to stack blocks, except the toddler occasionally writes LINQ queries.

For example:

User: Who is Percy Henry Smith’s youngest child?

LLM reasoning:

1. Retrieve Percy’s ID using GetId("Percy Henry Smith").
2. Get a list of his children’s names.
3. Sort them by date of birth.
4. Pick the youngest.

Answer:
public static string answer() 
{             
  string id = GetId("Percy Henry Smith");

  if (id is null) return "I don't know who Percy Henry Smith is.";

  List<string> childrenNames = GetChildrenNames(id);        
  if (childrenNames.Count == 0) return "Percy Henry Smith has no known children.";         

  var sortedChildren = childrenNames.OrderBy(child => GetDOB(GetId(child))).ToList();
  string youngestChildName = sortedChildren.First();        

  return $"The youngest child of Percy Henry Smith is {youngestChildName}.";
}

This is where the code‑tool approach shines:

  • It’s explicit
  • It’s deterministic
  • It’s auditable
  • And when it goes wrong, you can point at the exact line and say “There. That’s where the LLM lost the plot.”

(Which, as we saw in Part IX, is often very entertaining.)

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *