RELEASE: Finalize Semantic Restructuring v0.1.0
Some checks failed
Deploy-Agent-V15-Stdin / JOB-V15-STDIN (push) Failing after 3s
Some checks failed
Deploy-Agent-V15-Stdin / JOB-V15-STDIN (push) Failing after 3s
- Folders: literate->harness, src->library, system->environment, scripts->interfaces. - Synchronized all :tangle paths and system definitions. - Hardened .gitignore for binary and log artifacts. - Consolidated all documentation into docs/.
This commit is contained in:
95
harness/context.org
Normal file
95
harness/context.org
Normal file
@@ -0,0 +1,95 @@
|
||||
#+TITLE: Peripheral Vision (context.lisp)
|
||||
#+AUTHOR: Amr
|
||||
#+FILETAGS: :harness:context:
|
||||
#+STARTUP: content
|
||||
|
||||
* Peripheral Vision (context.lisp)
|
||||
|
||||
** Architectural Intent: Contextual Awareness
|
||||
The Context stage (often referred to as "Peripheral Vision") is responsible for assembling the situational awareness that the Probabilistic Engine needs to make informed decisions.
|
||||
|
||||
In most agent frameworks, context is provided as a massive, unstructured text dump of recent chat history. OpenCortex takes a more sophisticated approach:
|
||||
1. **Foveal Focus:** The data immediately relevant to the current task (e.g., the specific Org headline being edited).
|
||||
2. **Peripheral Awareness:** Low-resolution metadata about the rest of the Memex (e.g., list of active projects, recent system logs, current time/location).
|
||||
3. **Semantic Retrieval:** Utilizing vector embeddings to pull in semantically related nodes from the long-term memory.
|
||||
|
||||
By balancing these three layers, we provide the agent with a "Wide Angle" view of the user's life without overflowing the LLM's context window.
|
||||
|
||||
** Pipeline Initialization
|
||||
#+begin_src lisp :tangle ../library/context.lisp
|
||||
(in-package :opencortex)
|
||||
#+end_src
|
||||
|
||||
* Awareness Assembly
|
||||
|
||||
** Project Awareness (context-get-active-projects)
|
||||
Identifies current active work by querying the Org Memory for nodes with the ~:PROJECT:~ tag or ~NEXT~ status.
|
||||
|
||||
#+begin_src lisp :tangle ../library/context.lisp
|
||||
(defun context-get-active-projects ()
|
||||
"Retrieves a list of project headlines currently marked as NEXT or in progress."
|
||||
(let ((all-projects (list-objects-with-attribute :CATEGORY "Project")))
|
||||
(loop for p in all-projects
|
||||
collect (list :id (org-object-id p)
|
||||
:title (getf (org-object-attributes p) :TITLE)))))
|
||||
#+end_src
|
||||
|
||||
** Historical Awareness (context-get-recent-completed-tasks)
|
||||
Provides short-term memory of what was recently achieved, allowing the agent to maintain continuity.
|
||||
|
||||
#+begin_src lisp :tangle ../library/context.lisp
|
||||
(defun context-get-recent-completed-tasks (&optional (limit 5))
|
||||
"Retrieves the last N tasks marked as DONE from the memory history."
|
||||
(let ((all-completed (list-objects-with-attribute :TODO "DONE")))
|
||||
(subseq (sort all-completed #'> :key #'org-object-version)
|
||||
0 (min limit (length all-completed)))))
|
||||
#+end_src
|
||||
|
||||
** Skill Awareness (context-list-all-skills)
|
||||
Allows the agent to understand its own capabilities by listing the human-readable descriptions of all loaded Literate Skills.
|
||||
|
||||
#+begin_src lisp :tangle ../library/context.lisp
|
||||
(defun context-list-all-skills ()
|
||||
"Returns a list of registered skills and their documentation."
|
||||
(let ((results nil))
|
||||
(maphash (lambda (id skill)
|
||||
(push (list :id id :name (skill-name skill)) results))
|
||||
*skills-registry*)
|
||||
results))
|
||||
#+end_src
|
||||
|
||||
** System Awareness (context-get-system-logs)
|
||||
Crucial for self-debugging. Provides the agent with the internal logs so it can explain why a previous action failed or was blocked by a Bouncer.
|
||||
|
||||
#+begin_src lisp :tangle ../library/context.lisp
|
||||
(defun context-get-system-logs ()
|
||||
"Retrieves the in-memory circular log buffer."
|
||||
(bt:with-lock-held (*logs-lock*)
|
||||
(format nil "~{~a~%~}" (reverse *system-logs*))))
|
||||
#+end_src
|
||||
|
||||
* Global Context Generation
|
||||
|
||||
** Awareness Assembly (context-assemble-global-awareness)
|
||||
This function acts as the "Contextual Conductor." It synthesizes the various awareness layers into a single, high-signal string suitable for the LLM system prompt.
|
||||
|
||||
#+begin_src lisp :tangle ../library/context.lisp
|
||||
(defun context-assemble-global-awareness ()
|
||||
"Assembles the full context block for a neural request."
|
||||
(let ((projects (context-get-active-projects))
|
||||
(time (multiple-value-bind (s m h d mo y) (get-decoded-time) (format nil "~a-~a-~a ~a:~a:~a" y mo d h m s))))
|
||||
(format nil "CURRENT_TIME: ~a. ACTIVE_PROJECTS: ~s. FOVEAL_FOCUS: ~a"
|
||||
time
|
||||
projects
|
||||
(or *foveal-focus-id* "None"))))
|
||||
#+end_src
|
||||
|
||||
** Semantic Context Query (context-query-store)
|
||||
A hook for future vector-based retrieval. In the MVP, it performs a simple keyword search over the Memory graph.
|
||||
|
||||
#+begin_src lisp :tangle ../library/context.lisp
|
||||
(defun context-query-store (query &key (limit 5))
|
||||
"Placeholder for semantic/vector search over the Memex."
|
||||
(declare (ignore query limit))
|
||||
nil)
|
||||
#+end_src
|
||||
Reference in New Issue
Block a user