AgentLogic
AgentLogic
module is responsible for handling a single iteration of the logic part of the agent, i.e. without executing any external tool. In this role AgentLogic
is the sole place of full agent where we interact with the language model.
AgentLogic
object is initialized as:
def __init__(
self,
context: AgentContext,
model: LLM,
prompt_strategy: PromptStrategy,
stop_word: Optional[str] = None,
) -> None
A generic AgentLogic
class brings the run
method that represents this single iteration. This function is:
def run(
self,
instruction: str,
short_memory: ShortMemory
) -> str:
# History
history = short_memory.get_all()
# Assemble the messages
msgs = self._prompt_strategy.render(
instruction,
history
)
# Run the LLM
output = self._llm.run(
msgs,
self._stop_word
)
# Process the response
response = self.process_response(output)
return response
AgentLogic
uses language model object defined in the llm
module. This module is discussed in details in the Language and Embedding Models Abstraction section.
Example Agent Logic Instantiation
agent_context = AgentContext(
agent_name="TestAgent",
agent_persona="Researcher always following scientific method",
)
llm_factory = LLMFactory()
llm_model = llm_factory.create("ollama|gemma3")
template = FileTemplate(
agent_context.model_dump(),
"ReAct.template"
)
strategy = ReactPrompt(
system_template=template,
tool_dictionary={},
)
sm = ShortMemory(capacity=5)
agent_logic = GenericAgentLogic(
context=agent_context,
model=llm_model,
prompt_strategy=strategy,
stop_word="<PAUSE>",
)
INSTRUCTION = "Why is the sky blue?"
result = agent_logic.run(
instruction=INSTRUCTION,
short_memory=sm
)
In this example we create a simple agent with the ReAct
prompt strategy. The agent is initialized with the AgentContext
, LLM
, PromptStrategy
and the stop word.
The agent's logic is then run with the instruction and the short memory. The result of the execution is returned as a string.
The setup of the agent logic may seem cumbersome as it involves number of objects and steps. As such, in Elemental it is included in the full agent initialization. However, all components are exposed for user to build more custom solution.