Adapters¶
tac.adapters ¶
Adapters for integrating with external services in the Twilio Agent Connect.
AdapterOptions ¶
Bases: BaseModel
Options for configuring how adapters inject memory and profile data.
Example
Default behavior (no options) - inject ALL profile traits¶
client = with_tac_memory(openai_client, memory_response, context)
Default behavior (options but no profile_traits specified) - inject ALL profile traits¶
options = AdapterOptions() client = with_tac_memory(openai_client, memory_response, context, options=options)
Explicitly exclude all profile traits¶
options = AdapterOptions(profile_traits=None) client = with_tac_memory(openai_client, memory_response, context, options=options)
or¶
options = AdapterOptions(profile_traits=[]) client = with_tac_memory(openai_client, memory_response, context, options=options)
Specific traits only¶
options = AdapterOptions(profile_traits=["Contact", "Preferences"]) client = with_tac_memory(openai_client, memory_response, context, options=options)
get_profile_traits ¶
get_profile_traits() -> list[str] | None
Get the profile traits to include.
Returns:
| Type | Description |
|---|---|
list[str] | None
|
None to include all traits (when field not set), |
list[str] | None
|
empty list to exclude all (when explicitly set to None or []), |
list[str] | None
|
or list of specific trait group names to include. |
MemoryPromptBuilder ¶
Builds LLM prompts from TAC memory and profile data.
This class orchestrates prompt building by calling helper methods on TACMemoryResponse and ConversationSession models, then assembles the sections into a complete prompt.
Example
prompt = MemoryPromptBuilder.build(memory_response, context, options) if prompt: ... # Inject into your LLM messages ... messages.insert(0, {"role": "system", "content": prompt})
build
staticmethod
¶
build(
memory_response: TACMemoryResponse | None = None,
context: ConversationSession | None = None,
options: AdapterOptions | None = None,
) -> str | None
Build a complete memory prompt from TAC data.
This is the main entry point. Delegates formatting to model helper methods, then assembles sections into a complete prompt.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
memory_response
|
TACMemoryResponse | None
|
Memory data from TAC.retrieve_memory() |
None
|
context
|
ConversationSession | None
|
Conversation session with profile data |
None
|
options
|
AdapterOptions | None
|
Adapter options for trait filtering |
None
|
Returns:
| Type | Description |
|---|---|
str | None
|
Formatted prompt string ready for LLM injection, or None if |
str | None
|
no memory/profile data is available. |
Example
prompt = MemoryPromptBuilder.build( ... memory_response=memory_response, ... context=context, ... options=AdapterOptions(profile_traits=["Contact"]), ... ) print(prompt)
Customer Context¶
You have access to the following information about this customer from previous interactions:
Customer Profile¶
Information about this customer: - Contact: {"name": "John Doe", "email": "john@example.com"}
Key Observations¶
Important notes about the customer from previous interactions: - Customer prefers email communication
compose
staticmethod
¶
compose(
system_prompt: str | None = None,
memory_response: TACMemoryResponse | None = None,
context: ConversationSession | None = None,
options: AdapterOptions | None = None,
) -> str
Compose system prompt with memory context.
Appends memory to system_prompt if available. Always returns a string.
Example
prompt = MemoryPromptBuilder.compose( ... "You are a helpful assistant", memory_response, context ... )