agents.conversation.base.example

Base Conversation Agent Example.

This example demonstrates how to create custom conversation agents by extending the BaseConversationAgent class and implementing core conversation patterns.

Exceptions

ConversationError

Placeholder for conversation errors.

Classes

CustomConversationAgent

Custom conversation agent demonstrating extension patterns.

CustomConversationState

Extended conversation state with quality tracking.

Functions

main()

Demonstrate custom conversation agent usage.

Module Contents

exception agents.conversation.base.example.ConversationError

Bases: Exception

Placeholder for conversation errors.

Initialize self. See help(type(self)) for accurate signature.

class agents.conversation.base.example.CustomConversationAgent(*args, **kwargs)

Bases: haive.agents.conversation.base.BaseConversationAgent

Custom conversation agent demonstrating extension patterns.

This example shows how to: - Implement custom speaker selection logic - Add conversation quality assessment - Handle errors gracefully - Track custom metrics

Initialize with custom configuration.

async execute_agent(agent, input_data, state)

Execute agent with quality assessment and error handling.

Parameters:
Return type:

str

get_conversation_summary()

Generate comprehensive conversation summary.

Return type:

dict[str, Any]

select_next_speaker(state)

Custom speaker selection with engagement-based prioritization.

Selects speakers based on: 1. Who hasn’t spoken in the current round 2. Engagement level preferences 3. Balanced participation

Parameters:

state (CustomConversationState)

Return type:

str | None

should_end_conversation(state)

Enhanced termination logic with quality considerations.

Ends conversation if: - Round limit reached - Quality drops below threshold - Engagement is too low - Explicit end flag set

Parameters:

state (CustomConversationState)

Return type:

bool

class agents.conversation.base.example.CustomConversationState(/, **data)

Bases: haive.agents.conversation.base.ConversationState

Extended conversation state with quality tracking.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Parameters:

data (Any)

property average_quality: float

Calculate average conversation quality.

Return type:

float

async agents.conversation.base.example.main()

Demonstrate custom conversation agent usage.