refactor: LLM Typen und Traits nach nazarick-core verschoben, BaseAgent extrahiert
This commit is contained in:
@@ -1,74 +1,38 @@
|
||||
/// Sebas Tian — Haupt-Butler-Agent von Nazarick.
|
||||
/// Implementiert den Agent-Trait und orchestriert
|
||||
/// LLM-Kommunikation, Prompt-Aufbau und Konversationsverlauf.
|
||||
// crates/sebas-tian/src/lib.rs
|
||||
//
|
||||
// Sebas Tian — Haupt-Butler-Agent.
|
||||
// Dünner Wrapper um BaseAgent — nur name() ist Sebas-spezifisch.
|
||||
|
||||
use nazarick_core::agent::BaseAgent;
|
||||
use nazarick_core::traits::Agent;
|
||||
use nazarick_core::types::AgentId;
|
||||
use nazarick_core::prompt::PromptBuilder;
|
||||
use api::llm::{LlmProvider, LlmRequest, Message};
|
||||
use nazarick_core::llm::LlmProvider;
|
||||
|
||||
pub struct Sebas {
|
||||
/// Eindeutige ID dieser Agent-Instanz
|
||||
id: AgentId,
|
||||
/// Baut den System-Prompt aus soul_core + soul_personality
|
||||
prompt_builder: PromptBuilder,
|
||||
/// Das LLM-Backend (LmStudio, Ollama, Mistral)
|
||||
llm: Box<dyn LlmProvider>,
|
||||
/// Konversationsverlauf — damit Sebas den Kontext behält
|
||||
history: Vec<Message>,
|
||||
base: BaseAgent,
|
||||
}
|
||||
|
||||
impl Sebas {
|
||||
/// Erstellt eine neue Sebas-Instanz.
|
||||
/// `soul_core_path` → Pfad zu soul_core.md
|
||||
/// `soul_personality_path` → Pfad zu soul_personality.md
|
||||
/// `llm` → LLM-Provider (z.B. LmStudioProvider)
|
||||
pub fn new(
|
||||
soul_core_path: impl Into<String>,
|
||||
soul_personality_path: impl Into<String>,
|
||||
llm: Box<dyn LlmProvider>,
|
||||
) -> Self {
|
||||
Self {
|
||||
id: AgentId::new_v4(),
|
||||
prompt_builder: PromptBuilder::new(soul_core_path, soul_personality_path),
|
||||
llm,
|
||||
history: Vec::new(),
|
||||
base: BaseAgent::new(soul_core_path, soul_personality_path, llm),
|
||||
}
|
||||
}
|
||||
|
||||
/// Sendet eine Nachricht an Sebas und gibt seine Antwort zurück.
|
||||
/// Der Konversationsverlauf wird automatisch mitgeführt.
|
||||
/// Delegiert chat() an BaseAgent.
|
||||
pub async fn chat(&mut self, user_message: &str) -> nazarick_core::types::Result<String> {
|
||||
// System-Prompt aus soul-Dateien aufbauen
|
||||
let system_prompt = self.prompt_builder.build()?;
|
||||
|
||||
// User-Nachricht zum Verlauf hinzufügen
|
||||
self.history.push(Message::user(user_message));
|
||||
|
||||
// Vollständige Nachrichtenliste aufbauen:
|
||||
// System-Prompt + gesamter bisheriger Verlauf
|
||||
let mut messages = vec![Message::system(system_prompt)];
|
||||
messages.extend(self.history.clone());
|
||||
|
||||
// LLM anfragen
|
||||
let request = LlmRequest {
|
||||
messages,
|
||||
max_tokens: 4096, // ← erhöht damit Thinking + Antwort reinpassen
|
||||
temperature: 0.7,
|
||||
};
|
||||
|
||||
let response = self.llm.complete(request).await?;
|
||||
|
||||
// Antwort zum Verlauf hinzufügen damit Sebas sich erinnert
|
||||
self.history.push(Message::assistant(&response.content));
|
||||
|
||||
Ok(response.content)
|
||||
self.base.chat(user_message).await
|
||||
}
|
||||
}
|
||||
|
||||
impl Agent for Sebas {
|
||||
fn id(&self) -> AgentId {
|
||||
self.id
|
||||
self.base.id
|
||||
}
|
||||
|
||||
fn name(&self) -> &str {
|
||||
|
||||
Reference in New Issue
Block a user