Reasoning agent#

 1# You may need to add your working directory to the Python path. To do so, uncomment the following lines of code
 2# import sys
 3# sys.path.append("/Path/to/directory/agentic-framework") # Replace with your directory path
 4
 5"""Reasoning-state example agent.
 6
 7Demonstrates the new BAF reasoning extension:
 8    * markdown skills loaded from a folder
 9    * Python tools loaded from a sibling module + decorator-registered tool
10    * a workspace pointing at the example directory itself, so the LLM can
11      browse and read the example files on demand
12    * a single predefined reasoning state wired up with ``use_reasoning_state``
13
14Run with the existing config file (``config_marcos.yaml``) and the OpenAI key
15already used by the other examples.
16"""
17
18import logging
19import os
20
21from baf.core.agent import Agent
22from baf.exceptions.logger import logger
23from baf.library.state import new_reasoning_state
24from baf.nlp.llm.llm_openai_api import LLMOpenAI
25from baf.platforms.websocket import WEBSOCKET_PORT
26
27# Configure the logging module (optional)
28logger.setLevel(logging.DEBUG)
29
30# Create the agent
31agent = Agent("reasoning_agent")
32# Load agent properties stored in a dedicated file
33agent.load_properties("config_marcos.yaml")
34agent.set_property(WEBSOCKET_PORT, 8775)
35# Define the platform your agent will use
36websocket_platform = agent.use_websocket_platform(use_ui=True)
37
38# Create the LLM (must support tool-calling — LLMOpenAI does).
39gpt = LLMOpenAI(
40    agent=agent,
41    name="gpt-5.4-mini",
42    parameters={},
43    num_previous_messages=10,
44)
45
46# --- Skills (markdown files) ---------------------------------------------- #
47
48_HERE = os.path.dirname(os.path.abspath(__file__))
49agent.load_skills(os.path.join(_HERE, "reasoning_skills"))
50agent.new_skill(
51    "Always greet the user by name when they introduce themselves.",
52    name="GreetByName",
53)
54
55# --- Tools (Python callables) --------------------------------------------- #
56
57# Bulk-register every public callable defined in reasoning_tools.py.
58agent.load_tools(os.path.join(_HERE, "reasoning_tools.py"))
59
60
61# Add a one-off tool with the decorator form.
62@agent.tool
63def echo(text: str) -> str:
64    """Echo the user-supplied text back, unchanged."""
65    return text
66
67
68# --- Workspace (filesystem the agent can browse) -------------------------- #
69
70# Point the agent at the examples folder so it can list and read example files
71# on demand. Replace with any folder you want the agent to explore.
72agent.new_workspace(_HERE + "\\workspace", name="cinema", writable=True)
73
74# --- Reasoning state ------------------------------------------------------ #
75
76# Single predefined state that runs the LLM-driven think→act→observe loop.
77reasoning_state = new_reasoning_state(agent=agent, llm=gpt, max_steps=30)
78reasoning_state.when_event().go_to(reasoning_state)
79
80
81# RUN APPLICATION
82
83if __name__ == "__main__":
84    agent.run()