Generate Insights over your agent chat histories.
generate_insights(
self,
*,
chat_histories: list[list[dict]],
instructions: str = DEFAULT_INSTRUCTIONS,
name: str | None = None,
model: Literal['openai', 'anthropic'] | None = None,
openai_api_key: str | None = None,
anthropic_api_key: str | None = None
) -> ls_schemas.InsightsReportExample:
import os
from langsmith import Client
client = client()
chat_histories = [
[
{"role": "user", "content": "how are you"},
{"role": "assistant", "content": "good!"},
],
[
{"role": "user", "content": "do you like art"},
{"role": "assistant", "content": "only Tarkovsky"},
],
]
report = client.generate_insights(
chat_histories=chat_histories,
name="Conversation Topics",
instructions="What are the high-level topics of conversations users are having with the assistant?",
openai_api_key=os.environ["OPENAI_API_KEY"],
)
# client.poll_insights(report=report)| Name | Type | Description |
|---|---|---|
chat_histories* | list[list[dict]] | A list of chat histories. Each chat history should be a list of messages. We recommend formatting these as OpenAI messages with a "role" and "content" key. Max length 1000 items. |
instructions | str | Default: DEFAULT_INSTRUCTIONSInstructions for the Insights agent. Should focus on what your agent does and what types of insights you want to generate. |
name | str | None | Default: NoneName for the generated Insights report. |
model | Literal['openai', 'anthropic'] | None | Default: NoneWhether to use OpenAI or Anthropic models. This will impact the cost of generating the Insights Report. |
openai_api_key | str | None | Default: NoneOpenAI API key to use. Only needed if you have not already stored this in LangSmith as a workspace secret. |
anthropic_api_key | str | None | Default: NoneAnthropic API key to use. Only needed if you have not already stored this in LangSmith as a workspace secret. |