Implement LLMInferenceActivity integration for Temporal workflows
Workflow Input Structure:
├─ question: User content for reasoning
├─ project: Project ID for scoping
├─ operations: Flags for link_entities, infer_facts, reason_query, summarize
└─ llm_activity: Configuration for LLMInferenceActivity
├─ model: Selected based on complexity (reasoning|ornith:35b|qwen2.5:3b)
├─ system_prompt: Task-specific instruction (Zep-backed)
├─ user_prompt: Content to process
├─ temperature: 0.7 (reasoning) or 0.5 (validation)
└─ max_tokens: 2048 (reasoning) or 512 (validation)
Model Selection:
├─ reason_query=true, summarize=true → reasoning (DeepSeek-R1, complex)
├─ reason_query=true, summarize=false → ornith:35b (medium)
└─ reason_query=false → qwen2.5:3b (fast, <100ms)
System Prompts (handlers/llm_prompts.rs):
├─ entity_extraction_system_prompt(): Extract entities + relationships + facts
├─ reasoning_system_prompt(): Step-by-step reasoning + answers
├─ agent_capability_validation_prompt(): Validate agent capabilities
└─ fact_validation_system_prompt(): Detect contradictions
Workflow Activity Execution:
├─ Temporal receives workflow input with llm_activity config
├─ ReasoningWorkflow orchestrates:
│ ├─ Activity 1: RetrieveMemory (optional context)
│ ├─ Activity 2: LLMInferenceActivity (calls /v1/chat/completions via gateway)
│ │ └─ Retries: 3× with backoff (2s, 4s, 8s)
│ │ └─ Timeout: 120s
│ │ └─ JWT propagation: Authorization: Bearer header
│ ├─ Activity 3: PersistResults (save to memory_entity/memory_edge)
│ └─ Activity 4: SummarizeFindings (return results)
├─ Memory handler polls DESCRIBE_WORKFLOW (30× with 100ms delay, 3s timeout)
└─ Returns ReasoningResult with answers, confidence, reasoning_steps
Changes:
├─ execute_reasoning_workflow(): Build llm_activity config with model selection
├─ select_llm_model(): Choose model based on operation complexity
├─ build_system_prompt(): Use Zep-inspired prompts for reasoning
├─ handlers/llm_prompts.rs: Centralized prompt templates (5 system + 4 user builders)
├─ AgentInitialization: Include llm_activity for capability validation
└─ Fixed duplicate extract_jwt_token call in agent_handler.rs
Activity Contract:
├─ Workflow input includes llm_activity block
├─ Temporal passes to LLMInferenceActivity
├─ Activity substitutes {{ previous_output }} template variables
├─ Activity calls POST /v1/chat/completions with JWT header
├─ Activity returns { response, model, stop_reason, tokens_used }
├─ PersistResults activity stores results to DB
└─ Workflow returns: question, answers[], confidence, reasoning_steps[]
Tests Added:
+ 14 new tests in llm_prompts.rs (prompt validation, user prompt builders)
Compilation: ✅
This commit is contained in:
@@ -97,17 +97,27 @@ pub async fn register_agent_handler(
|
||||
// 1. Persist agent state to temporal_workflow_links table
|
||||
// 2. Execute LLMInferenceActivity (call LLM via api.riotpiao.com/v1/chat/completions)
|
||||
// 3. Store reasoning traces to memory_entity/memory_edge
|
||||
if let Some(jwt) = crate::handlers::crate::handlers::extract_jwt_token(&req) {
|
||||
if let Some(jwt) = crate::handlers::extract_jwt_token(&req) {
|
||||
let client = SynthesisClient::new(
|
||||
"https://api.riotpiao.com".to_string(),
|
||||
jwt,
|
||||
);
|
||||
|
||||
// Start Temporal workflow for agent initialization
|
||||
// Include LLMInferenceActivity configuration for capability verification
|
||||
let workflow_input = serde_json::json!({
|
||||
"agent_id": body.agent_id,
|
||||
"capabilities": body.capabilities,
|
||||
"project_id": body.project_id
|
||||
"project_id": body.project_id,
|
||||
|
||||
// LLMInferenceActivity inputs for agent capability reasoning
|
||||
"llm_activity": {
|
||||
"model": "ornith:13b",
|
||||
"system_prompt": "You are an agent capability validator. Verify that the requested capabilities are valid for the memory system. Return JSON with 'valid' boolean and 'reason' string.",
|
||||
"user_prompt": format!("Validate agent capabilities: {:?}", body.capabilities),
|
||||
"temperature": 0.5,
|
||||
"max_tokens": 512
|
||||
}
|
||||
});
|
||||
|
||||
let workflow_req = crate::handlers::WorkflowBuilder::new("AgentInitialization")
|
||||
|
||||
Reference in New Issue
Block a user