Understanding and implementing the agent loop in TextLayer Core
backend/textlayer/services/llm/client/chat.py
max_steps
times (default: 10)_is_thread_finished()
: Determines if conversation has naturally concluded
_check_termination_conditions()
: Checks for timeout conditions
_terminate_thread()
: Creates termination messages when limits are reached
backend/textlayer/commands/threads/process_chat_message.py
This command encapsulates the business logic for processing chat messages and provides the interface between the controller layer and the LLM services.
Key Features:
agent_loop
boolean parameterbackend/textlayer/controllers/thread_controller.py
Provides a clean interface for the route layer to process chat messages:
backend/textlayer/routes/thread_routes.py
Currently, the HTTP API endpoints (/chat
and /chat/stream
) have agent_loop=False
hardcoded, meaning the agent loop is not exposed via the REST API. This suggests it’s primarily used for internal processing or CLI operations.
backend/textlayer/cli/threads/process_chat_message.py
Provides a clean interface for programmatic access to the agent loop:
agent_loop=True
)False
)