Nodes

Nodes contain your agent logic. They process events, maintain conversation context, and generate responses from LLMs.

What is a Node?

Nodes are where the “thinking” happens in your agent system. It contain the business logic and LLM interactions.

Basic Example

1from line.nodes import ReasoningNode
2from line.events import AgentResponse
3
4
5class ChatNode(ReasoningNode):
6 def __init__(self, system_prompt, llm_client):
7 super().__init__(system_prompt=system_prompt)
8 self.llm_client = llm_client
9
10 async def process_context(self, context):
11 # Get conversation history and system prompt
12 messages = self.format_for_llm(context.events)
13
14 # Generate response from LLM
15 response = await self.llm_client.generate(messages)
16
17 # Yield response to be spoken to user
18 yield AgentResponse(content=response)

Node Types

| Type | Description | |------|-------------| | Node | Base class for all nodes | | ReasoningNode | Template for conversational agents with automatic context management |

ReasoningNode is the base class for all nodes that use LLMs. Users should implement the process_context() method to process messages and yield events asynchronously.

Key Features

  • Event Processing: Receive and process events from bridges
  • State Management: Maintain conversation history and context
  • Response Generation: Yield events back through the system
  • Lifecycle Hooks: start() method for async initialization

Nodes can work together in multi-agent systems. See Agent Patterns for coordination examples.