Nous.Tools.StringTools (nous v0.13.3)

View Source

Built-in tools for string manipulation operations.

These tools provide common string functionality that AI agents often need:

  • Text transformation (uppercase, lowercase, capitalize)
  • String analysis (length, count occurrences)
  • String operations (replace, split, join, trim)
  • Pattern matching and extraction
  • String validation

Usage

agent = Nous.new("lmstudio:qwen3-vl-4b-thinking-mlx",
  tools: [
    &StringTools.string_length/2,
    &StringTools.replace_text/2,
    &StringTools.split_text/2
  ]
)

{:ok, result} = Nous.run(agent, "How many characters in 'Hello World'?")

Summary

Functions

Capitalize the first letter of each word.

Check if a string contains a substring.

Count occurrences of a substring in a string.

Check if a string ends with a suffix.

Extract numbers from a string.

Extract words from a string.

Check if a string is a palindrome.

Join a list of strings with a delimiter.

Pad a string to a specific length.

Repeat a string N times.

Replace all occurrences of a pattern in a string.

Reverse a string.

Split a string into parts based on a delimiter.

Check if a string starts with a prefix.

Get the length of a string.

Extract a substring from a string.

Convert text to lowercase.

Convert text to uppercase.

Trim whitespace from a string.

Functions

capitalize_text(ctx, args)

Capitalize the first letter of each word.

Arguments

  • text: The text to capitalize
  • mode: "first" (first letter only), "words" (each word), "sentences" (each sentence)

contains(ctx, args)

Check if a string contains a substring.

Arguments

  • text: The text to search in
  • pattern: The pattern to search for
  • case_sensitive: Whether to match case (default: true)

count_occurrences(ctx, args)

Count occurrences of a substring in a string.

Arguments

  • text: The text to search in
  • pattern: The pattern to count
  • case_sensitive: Whether to match case (default: true)

ends_with(ctx, args)

Check if a string ends with a suffix.

Arguments

  • text: The text to check
  • suffix: The suffix to check for
  • case_sensitive: Whether to match case (default: true)

extract_numbers(ctx, args)

Extract numbers from a string.

Arguments

  • text: The text to extract numbers from

extract_words(ctx, args)

Extract words from a string.

Arguments

  • text: The text to extract words from
  • min_length: Minimum word length (default: 1)

is_palindrome(ctx, args)

Check if a string is a palindrome.

Arguments

  • text: The text to check
  • ignore_case: Whether to ignore case (default: true)
  • ignore_spaces: Whether to ignore spaces (default: true)

join_text(ctx, args)

Join a list of strings with a delimiter.

Arguments

  • parts: List of strings to join (comma-separated string)
  • delimiter: The delimiter to use (default: " ")

pad_text(ctx, args)

Pad a string to a specific length.

Arguments

  • text: The text to pad
  • length: Target length
  • padding: Character to pad with (default: " ")
  • side: "left", "right", or "both" (default: "right")

repeat_text(ctx, args)

Repeat a string N times.

Arguments

  • text: The text to repeat
  • times: Number of times to repeat (max 100)

replace_text(ctx, args)

Replace all occurrences of a pattern in a string.

Arguments

  • text: The original text
  • pattern: The text to find
  • replacement: The text to replace with
  • case_sensitive: Whether to match case (default: true)

reverse_text(ctx, args)

Reverse a string.

Arguments

  • text: The text to reverse

split_text(ctx, args)

Split a string into parts based on a delimiter.

Arguments

  • text: The text to split
  • delimiter: The delimiter to split on (default: " ")
  • trim: Whether to trim whitespace from parts (default: false)
  • remove_empty: Whether to remove empty strings (default: false)

starts_with(ctx, args)

Check if a string starts with a prefix.

Arguments

  • text: The text to check
  • prefix: The prefix to check for
  • case_sensitive: Whether to match case (default: true)

string_length(ctx, args)

Get the length of a string.

Arguments

  • text: The string to measure

substring(ctx, args)

Extract a substring from a string.

Arguments

  • text: The original text
  • start: Starting position (0-indexed)
  • length: Number of characters to extract (optional, extracts to end if not provided)

to_lowercase(ctx, args)

Convert text to lowercase.

Arguments

  • text: The text to convert

to_uppercase(ctx, args)

Convert text to uppercase.

Arguments

  • text: The text to convert

trim_text(ctx, args)

Trim whitespace from a string.

Arguments

  • text: The text to trim
  • side: "both" (default), "left", "right"