Ai knowledge and logicHelpers

llm_summarize

Summarize a conversation, or any text, using an LLM.

llm_summarize(context: dict, prompt: str, input=None, max_words=None, fallback=None) -> str

Summarizes text according to an instruction. With no input, it summarizes the current conversation's transcript — which is the usual case when handing a ticket to another system.


Parameters

NameTypeDescription
contextdictThe context object passed to your action
promptstrWhat the summary should capture
inputanyOptional text to summarize instead of the conversation. Non-strings are converted to JSON.
max_wordsintOptional upper bound on summary length
fallbackstrReturned if the call fails. If omitted, the exception is raised.

Returns

str — the summary.


Examples

Write a ticket description when escalating

def execute_action(context):
    summary = llm_summarize(
        context,
        prompt=(
            "Summarize this conversation for the warehouse team. Lead with the "
            "problem in one sentence, then list any order numbers and dates."
        ),
        max_words=120,
        fallback="(summary unavailable)",
    )

    add_conversation_note(context, summary)
    return {"summary": summary}

Summarize something other than the conversation

def execute_action(context):
    order = fetch_order(context["args"]["orderId"])

    return llm_summarize(
        context,
        prompt="Describe this order in one sentence a customer would understand.",
        input=order,
        max_words=40,
    )

Summarization calls an LLM, so it takes a few seconds and costs tokens. For a yes/no question use llm_classify_binary, which is cheaper and faster.

On this page