llm_summarize
Summarize the current conversation or any text with an LLM, following your instruction.
llm_summarize(context: dict, prompt: str, input=None, max_words=None, fallback=None) -> strSummarizes text according to your instruction. With no input, it summarizes the current conversation's transcript. That is the usual case when you hand a ticket to another system, so the people there can act without reading the whole conversation.
Parameters
| Name | Type | Description |
|---|---|---|
context | dict | The context object passed to your action |
prompt | str | What the summary should capture. At most 2,000 characters |
input | any | Optional text to summarize instead of the conversation. Non-strings are converted to JSON. At most 100,000 characters after conversion |
max_words | int | Optional upper bound on summary length, at most 2,000 |
fallback | str | Returned if the call fails. If omitted, the exception is raised. |
Returns
str: the summary.
Error handling
- A request over the limits above is rejected. Without
fallback, the raisedrequests.HTTPErrornames the field and the limit that was exceeded. - With
fallback, any error, including that rejection, silently returns the fallback. Keep long instructions under the prompt limit, or a fallback can quietly replace every result.
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.