Initial commit

Co-Authored-By: Quentin Torroba <quentin.torroba@mistral.ai>
Co-Authored-By: Laure Hugo <laure.hugo@mistral.ai>
Co-Authored-By: Benjamin Trom <benjamin.trom@mistral.ai>
Co-Authored-By: Mathias Gesbert <mathias.gesbert@ext.mistral.ai>
Co-Authored-By: Michel Thomazo <michel.thomazo@mistral.ai>
Co-Authored-By: Clément Drouin <clement.drouin@mistral.ai>
Co-Authored-By: Vincent Guilloux <vincent.guilloux@mistral.ai>
Co-Authored-By: Valentin Berard <val@mistral.ai>
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
Quentin Torroba 2025-12-09 13:13:22 +01:00 committed by Quentin Torroba
commit fa15fc977b
200 changed files with 30484 additions and 0 deletions

64
vibe/core/programmatic.py Normal file
View file

@ -0,0 +1,64 @@
from __future__ import annotations
import asyncio
from vibe.core.agent import Agent
from vibe.core.config import VibeConfig
from vibe.core.output_formatters import create_formatter
from vibe.core.types import AssistantEvent, LLMMessage, OutputFormat, Role
from vibe.core.utils import ConversationLimitException, logger
def run_programmatic(
config: VibeConfig,
prompt: str,
max_turns: int | None = None,
max_price: float | None = None,
output_format: OutputFormat = OutputFormat.TEXT,
previous_messages: list[LLMMessage] | None = None,
auto_approve: bool = True,
) -> str | None:
"""Run in programmatic mode: execute prompt and return the assistant response.
Args:
config: Configuration for the Vibe agent
prompt: The user prompt to process
max_turns: Maximum number of assistant turns (LLM calls) to allow
max_price: Maximum cost in dollars before stopping
output_format: Format for the output
previous_messages: Optional messages from a previous session to continue
auto_approve: Whether to automatically approve tool execution
Returns:
The final assistant response text, or None if no response
"""
formatter = create_formatter(output_format)
agent = Agent(
config,
auto_approve=auto_approve,
message_observer=formatter.on_message_added,
max_turns=max_turns,
max_price=max_price,
enable_streaming=False,
)
logger.info("USER: %s", prompt)
async def _async_run() -> str | None:
if previous_messages:
non_system_messages = [
msg for msg in previous_messages if not (msg.role == Role.system)
]
agent.messages.extend(non_system_messages)
logger.info(
"Loaded %d messages from previous session", len(non_system_messages)
)
async for event in agent.act(prompt):
formatter.on_event(event)
if isinstance(event, AssistantEvent) and event.stopped_by_middleware:
raise ConversationLimitException(event.content)
return formatter.finalize()
return asyncio.run(_async_run())