Skip to content

Feature: Allow for templating of nested objects in instructions #574

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

whoisarpit
Copy link

@whoisarpit whoisarpit commented May 6, 2025

Fixes #575

Summary

Adds support for nested dot-separated references in instruction templates. Users can now access deeply nested values in the state object using a simple dot notation, with optional markers at any level of the path.

This is useful when templating structured data from a previous LlmAgent using output_schema.

Changes

  • Enhanced _populate_values function to handle nested dot-separated references
  • Supports optional markers at any level with ? suffix (e.g., {user?.profile?.name?})
  • Updated existing tests and added new test cases for the nested templating functionality

Examples

Before:

# Only simple values were supported
"{customerId}" -> "1234567890"
"{user:profile}" -> "basic"
"{user.profile.name}" -> "{user.profile.name}"

After:

# Now supports nested references
"{user.profile.name}" -> "John Doe"
"{user.settings.theme}" -> "dark"

# Optional markers at any level
"{user?.profile?.email}" -> "[email protected]"
"{user?.preferences?.theme?}" -> "" (empty if path doesn't exist)

# Invalid paths without optional markers will not be templated instead of throwing an error to avoid breaking changes
"{user.invalid.path}" -> "{user.invalid.path}"

Use Cases

  • Accessing complex nested objects in state
  • Optional references that gracefully handle missing values
  • Better organization of state data with hierarchical structures

This feature enables more flexible template interpolation, allowing for cleaner, more organized state structures while maintaining backward compatibility with the existing flat state model.

@whoisarpit whoisarpit force-pushed the feat/nested_populate branch from eb3b49c to 012ef17 Compare May 6, 2025 06:43
@whoisarpit whoisarpit force-pushed the feat/nested_populate branch from 012ef17 to cd10aa0 Compare May 7, 2025 02:19
@whoisarpit whoisarpit changed the title Feature: Allow for nested templating in instructions Feature: Allow for templating of nested objects in instructions May 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support templating of nested values in instruction template
1 participant