feat: add ephemeral prefill messages and system prompt loading

- Implemented functionality to load ephemeral prefill messages from a JSON file, enhancing few-shot priming capabilities for the agent.
- Introduced a mechanism to load an ephemeral system prompt from environment variables or configuration files, ensuring dynamic prompt adjustments at API-call time.
- Updated the CLI and agent initialization to utilize the new prefill messages and system prompt, improving the overall interaction experience.
- Enhanced configuration options with new environment variables for prefill messages and system prompts, allowing for greater customization without persistence.
This commit is contained in:
teknium1 2026-02-23 23:55:42 -08:00
parent a183827128
commit 2bf96ad244
7 changed files with 218 additions and 36 deletions

View file

@ -412,9 +412,17 @@ class ShellFileOperations(FileOperations):
# Still try to read, but warn
pass
# Check if it's an image - return base64
# Images are never inlined — redirect to the vision tool
if self._is_image(path):
return self._read_image(path)
return ReadResult(
is_image=True,
is_binary=True,
file_size=file_size,
hint=(
"Image file detected. Automatically redirected to vision_analyze tool. "
"Use vision_analyze with this file path to inspect the image contents."
),
)
# Read a sample to check for binary content
sample_cmd = f"head -c 1000 {self._escape_shell_arg(path)} 2>/dev/null"
@ -457,6 +465,10 @@ class ShellFileOperations(FileOperations):
hint=hint
)
# Images larger than this are too expensive to inline as base64 in the
# conversation context. Return metadata only and suggest vision_analyze.
MAX_IMAGE_BYTES = 512 * 1024 # 512 KB
def _read_image(self, path: str) -> ReadResult:
"""Read an image file, returning base64 content."""
# Get file size
@ -467,6 +479,17 @@ class ShellFileOperations(FileOperations):
except ValueError:
file_size = 0
if file_size > self.MAX_IMAGE_BYTES:
return ReadResult(
is_image=True,
is_binary=True,
file_size=file_size,
hint=(
f"Image is too large to inline ({file_size:,} bytes). "
"Use vision_analyze to inspect the image, or reference it by path."
),
)
# Get base64 content
b64_cmd = f"base64 -w 0 {self._escape_shell_arg(path)} 2>/dev/null"
b64_result = self._exec(b64_cmd, timeout=30)