Python Client SDK for the Mistral AI API with chat completions, embeddings, fine-tuning, and agent capabilities.
—
Experimental and preview APIs that provide access to cutting-edge features and capabilities. These APIs are in beta and may evolve as they mature. They provide advanced functionality for conversations, document libraries, and enhanced agent capabilities.
Manage conversational AI interactions with built-in function execution, streaming responses, and context management.
def start(
inputs: Union[ConversationInputs, dict],
instructions: Optional[str] = None,
tools: Optional[List[Tool]] = None,
**kwargs
) -> ConversationResponse:
"""
Start a new conversation.
Parameters:
- inputs: Initial conversation inputs and context
- instructions: Optional system instructions
- tools: Available tools for the conversation
Returns:
ConversationResponse with conversation ID and initial outputs
"""
async def start_async(
inputs: Union[ConversationInputs, dict],
**kwargs
) -> ConversationResponse:
"""
Async version of start method.
"""
def list(
limit: Optional[int] = None,
after: Optional[str] = None,
**kwargs
) -> List[AgentConversation]:
"""
List conversations.
Parameters:
- limit: Maximum number of conversations to return
- after: Cursor for pagination
Returns:
List of conversation objects
"""
def get(conversation_id: str, **kwargs) -> ConversationResponse:
"""
Get conversation details.
Parameters:
- conversation_id: Unique conversation identifier
Returns:
ConversationResponse with full conversation state
"""
def append(
conversation_id: str,
inputs: Union[ConversationInputs, dict],
**kwargs
) -> ConversationResponse:
"""
Append to an existing conversation.
Parameters:
- conversation_id: Conversation to append to
- inputs: New inputs to add to conversation
Returns:
Updated conversation response
"""
def restart(
conversation_id: str,
inputs: Union[ConversationInputs, dict],
**kwargs
) -> ConversationResponse:
"""
Restart a conversation with new inputs.
Parameters:
- conversation_id: Conversation to restart
- inputs: New starting inputs
Returns:
Restarted conversation response
"""Handle real-time conversational interactions with streaming responses.
def start_stream(
inputs: Union[ConversationInputs, dict],
instructions: Optional[str] = None,
tools: Optional[List[Tool]] = None,
**kwargs
) -> Iterator[ConversationEvents]:
"""
Start a streaming conversation.
Parameters:
- inputs: Initial conversation inputs
- instructions: Optional system instructions
- tools: Available tools
Returns:
Iterator of conversation events
"""
def append_stream(
conversation_id: str,
inputs: Union[ConversationInputs, dict],
**kwargs
) -> Iterator[ConversationEvents]:
"""
Stream append to existing conversation.
Parameters:
- conversation_id: Conversation to append to
- inputs: New inputs to add
Returns:
Iterator of conversation update events
"""
def restart_stream(
conversation_id: str,
inputs: Union[ConversationInputs, dict],
**kwargs
) -> Iterator[ConversationEvents]:
"""
Stream restart conversation.
Parameters:
- conversation_id: Conversation to restart
- inputs: New starting inputs
Returns:
Iterator of restart events
"""Create and manage document libraries to enhance agent capabilities with indexed document retrieval.
def create(
name: str,
description: Optional[str] = None,
metadata: Optional[dict] = None,
**kwargs
) -> LibraryOut:
"""
Create a new document library.
Parameters:
- name: Library name
- description: Optional description
- metadata: Optional metadata
Returns:
LibraryOut with library details
"""
def list(
limit: Optional[int] = None,
**kwargs
) -> ListLibraryOut:
"""
List document libraries.
Parameters:
- limit: Maximum number of libraries to return
Returns:
ListLibraryOut with library list
"""
def get(library_id: str, **kwargs) -> LibraryOut:
"""
Get library details.
Parameters:
- library_id: Unique library identifier
Returns:
LibraryOut with full library information
"""
def update(
library_id: str,
name: Optional[str] = None,
description: Optional[str] = None,
metadata: Optional[dict] = None,
**kwargs
) -> LibraryOut:
"""
Update library metadata.
Parameters:
- library_id: Library to update
- name: Updated name
- description: Updated description
- metadata: Updated metadata
Returns:
Updated LibraryOut
"""
def delete(library_id: str, **kwargs) -> dict:
"""
Delete a library.
Parameters:
- library_id: Library to delete
Returns:
Deletion confirmation
"""Manage documents within libraries for enhanced agent knowledge.
# Document operations are available through the libraries sub-API
def upload_document(
library_id: str,
file: Union[str, BinaryIO],
metadata: Optional[dict] = None,
**kwargs
) -> DocumentOut:
"""
Upload document to library.
Parameters:
- library_id: Target library
- file: Document file
- metadata: Document metadata
Returns:
DocumentOut with document details
"""
def list_documents(
library_id: str,
limit: Optional[int] = None,
**kwargs
) -> ListDocumentOut:
"""
List documents in library.
Parameters:
- library_id: Library to list from
- limit: Maximum documents to return
Returns:
ListDocumentOut with document list
"""Enhanced agent management with additional capabilities beyond the standard agents API.
def create(
name: str,
model: str,
description: Optional[str] = None,
instructions: Optional[str] = None,
**kwargs
) -> Agent:
"""
Create a beta agent with enhanced capabilities.
Parameters:
- name: Agent name
- model: Model to use
- description: Agent description
- instructions: System instructions
Returns:
Agent with beta features enabled
"""
def list(**kwargs) -> List[Agent]:
"""
List beta agents.
Returns:
List of beta-enabled agents
"""
def get(agent_id: str, **kwargs) -> Agent:
"""
Get beta agent details.
Parameters:
- agent_id: Agent identifier
Returns:
Agent with full beta configuration
"""
def update(
agent_id: str,
name: Optional[str] = None,
description: Optional[str] = None,
**kwargs
) -> Agent:
"""
Update beta agent.
Parameters:
- agent_id: Agent to update
- name: Updated name
- description: Updated description
Returns:
Updated agent
"""
def update_version(
agent_id: str,
version_data: dict,
**kwargs
) -> Agent:
"""
Update agent version with beta features.
Parameters:
- agent_id: Agent to update
- version_data: Version-specific configuration
Returns:
Agent with updated version
"""from mistralai import Mistral
from mistralai.models import ConversationInputs
client = Mistral(api_key="your-api-key")
# Start a conversation with beta API
inputs = ConversationInputs(
messages=[{"role": "user", "content": "Hello, I need help with data analysis."}]
)
conversation = client.beta.conversations.start(
inputs=inputs,
instructions="You are a data analysis expert. Help users analyze their data."
)
print(f"Started conversation: {conversation.id}")# Create a library for documentation
library = client.beta.libraries.create(
name="Technical Documentation",
description="Library of technical documentation and guides",
metadata={"domain": "software", "language": "en"}
)
print(f"Created library: {library.id}")
# Upload documents to the library (conceptual - exact API may vary)
# document = client.beta.libraries.upload_document(
# library_id=library.id,
# file="technical_guide.pdf",
# metadata={"type": "guide", "topic": "API"}
# )# Start streaming conversation
stream = client.beta.conversations.start_stream(
inputs=inputs,
instructions="Provide step-by-step analysis guidance."
)
for event in stream:
if event.type == "message_output":
print(f"Response: {event.content}")
elif event.type == "function_call":
print(f"Function called: {event.function_name}")class ConversationInputs:
messages: List[dict]
tools: Optional[List[Tool]]
metadata: Optional[dict]
class ConversationResponse:
id: str
object: str
created_at: int
outputs: List[dict]
usage: Optional[ConversationUsageInfo]
class ConversationEvents:
type: str
data: ConversationEventsData
id: Optional[str]
class ConversationEventsData:
content: Optional[str]
function_name: Optional[str]
arguments: Optional[dict]class LibraryOut:
id: str
object: str
name: str
description: Optional[str]
created_at: int
metadata: Optional[dict]
class ListLibraryOut:
object: str
data: List[LibraryOut]
class DocumentOut:
id: str
object: str
filename: str
library_id: str
created_at: int
metadata: Optional[dict]
class ListDocumentOut:
object: str
data: List[DocumentOut]Beta APIs are experimental and may change without notice. They should be used with caution in production environments. Key considerations:
When beta features graduate to stable APIs, migration guides will be provided to help transition existing implementations.
Beta APIs benefit from user feedback. Consider sharing your experience and use cases to help shape the final stable API design.
Install with Tessl CLI
npx tessl i tessl/pypi-mistralai