MCPcopy Create free account
hub / github.com/AQ-MedAI/MedMemoryBench / _step

Method _step

methods/letta/server/server.py:371–417  ·  view source on GitHub ↗

Send the input message through the agent

(
        self,
        actor: User,
        agent_id: str,
        input_messages: List[MessageCreate],
        interface: Union[AgentInterface, None] = None,  # needed to getting responses
        put_inner_thoughts_first: bool = True,
        # timestamp: Optional[datetime],
    )

Source from the content-addressed store, hash-verified

369 return Agent(agent_state=agent_state, interface=interface, user=actor, mcp_clients=self.mcp_clients)
370
371 def _step(
372 self,
373 actor: User,
374 agent_id: str,
375 input_messages: List[MessageCreate],
376 interface: Union[AgentInterface, None] = None, # needed to getting responses
377 put_inner_thoughts_first: bool = True,
378 # timestamp: Optional[datetime],
379 ) -> LettaUsageStatistics:
380 """Send the input message through the agent"""
381 # TODO: Thread actor directly through this function, since the top level caller most likely already retrieved the user
382 logger.debug(f"Got input messages: {input_messages}")
383 letta_agent = None
384 try:
385 letta_agent = self.load_agent(agent_id=agent_id, interface=interface, actor=actor)
386 if letta_agent is None:
387 raise KeyError(f"Agent (user={actor.id}, agent={agent_id}) is not loaded")
388
389 # Determine whether or not to token stream based on the capability of the interface
390 token_streaming = letta_agent.interface.streaming_mode if hasattr(letta_agent.interface, "streaming_mode") else False
391
392 logger.debug(f"Starting agent step")
393 if interface:
394 metadata = interface.metadata if hasattr(interface, "metadata") else None
395 else:
396 metadata = None
397
398 usage_stats = letta_agent.step(
399 input_messages=input_messages,
400 chaining=self.chaining,
401 max_chaining_steps=self.max_chaining_steps,
402 stream=token_streaming,
403 skip_verify=True,
404 metadata=metadata,
405 put_inner_thoughts_first=put_inner_thoughts_first,
406 )
407
408 except Exception as e:
409 logger.error(f"Error in server._step: {e}")
410 print(traceback.print_exc())
411 raise
412 finally:
413 logger.debug("Calling step_yield()")
414 if letta_agent:
415 letta_agent.interface.step_yield()
416
417 return usage_stats
418
419 def _command(self, user_id: str, agent_id: str, command: str) -> LettaUsageStatistics:
420 """Process a CLI command"""

Callers 4

_commandMethod · 0.95
user_messageMethod · 0.95
system_messageMethod · 0.95
send_messagesMethod · 0.95

Calls 5

load_agentMethod · 0.95
debugMethod · 0.65
errorMethod · 0.65
stepMethod · 0.45
step_yieldMethod · 0.45

Tested by

no test coverage detected