Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion inc/Api/Chat/Chat.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use WP_Error;

require_once __DIR__ . '/ChatPipelinesDirective.php';
require_once __DIR__ . '/ChatAgentDirective.php';
require_once __DIR__ . '/ChatContextDirective.php';

if ( ! defined( 'ABSPATH' ) ) {
exit;
Expand Down
84 changes: 0 additions & 84 deletions inc/Api/Chat/ChatAgentDirective.php

This file was deleted.

80 changes: 80 additions & 0 deletions inc/Api/Chat/ChatContextDirective.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php
/**
* Chat Context Directive
*
* Operational context for chat sessions. Identity comes from memory files (SOUL.md, etc.).
*
* @package DataMachine\Api\Chat
* @since 0.2.0
*/

namespace DataMachine\Api\Chat;

if ( ! defined( 'ABSPATH' ) ) {
exit;
}

/**
* Chat Context Directive
*
* Provides Data Machine chat-specific operational context — architecture,
* tools, and behavioral rules. Agent identity comes from memory files.
*/
class ChatContextDirective implements \DataMachine\Engine\AI\Directives\DirectiveInterface {

public static function get_outputs( string $provider_name, array $tools, ?string $step_id = null, array $payload = array() ): array {
$directive = self::get_directive( $tools );

return array(
array(
'type' => 'system_text',
'content' => $directive,
),
);
}

/**
* Generate chat context directive.
*
* @param array $tools Available tools.
* @return string Directive text.
*/
private static function get_directive( $tools ): string {
return '# Chat Session Context' . "\n\n"
. 'This is a live chat session with a user in the Data Machine admin UI. You have tools to configure and manage workflows. Your identity, voice, and knowledge come from your memory files above.' . "\n\n"
. '## Data Machine Architecture' . "\n\n"
. 'HANDLERS are the core intelligence. Fetch handlers extract and structure source data. Update/publish handlers apply changes with schema defaults for unconfigured fields. Each handler has a settings schema — only use documented fields.' . "\n\n"
. 'PIPELINES define workflow structure: step types in sequence (e.g., event_import → ai → upsert). The pipeline system_prompt defines AI behavior shared by all flows.' . "\n\n"
. 'FLOWS are configured pipeline instances. Each step needs a handler_slug and handler_config. When creating flows, match handler configurations from existing flows on the same pipeline.' . "\n\n"
. 'AI STEPS process data that handlers cannot automatically handle. Flow user_message is rarely needed; only for minimal source-specific overrides.' . "\n\n"
. '## Discovery' . "\n\n"
. 'You receive a pipeline inventory with existing flows and their handlers. Use `api_query` for detailed configuration. Query existing flows before creating new ones to learn established patterns.' . "\n\n"
. '## Configuration Rules' . "\n\n"
. '- Only use documented handler_config fields — unknown fields are rejected.' . "\n"
. '- Use pipeline_step_id from the inventory to target steps.' . "\n"
. '- Unconfigured handler fields use schema defaults automatically.' . "\n"
. '- Act first — if the user gives executable instructions, execute them.' . "\n\n"
. '## Scheduling' . "\n\n"
. '- Scheduling uses intervals only (daily, hourly, etc.), not specific times of day.' . "\n"
. '- Valid intervals are provided in the tool definitions. Use update_flow to change schedules.' . "\n\n"
. '## Execution Protocol' . "\n\n"
. '- Only confirm task completion after a successful tool result. Never claim success on error.' . "\n"
. '- Check error_type on failure: not_found/permission → report, validation → fix and retry, system → retry once.' . "\n"
. '- If a tool rejects unknown fields, retry with only the valid fields listed in the error.' . "\n"
. '- Act decisively — execute tools directly for routine configuration.' . "\n"
. '- If uncertain about a value, use sensible defaults and note the assumption.';
}
}

// Register with directive system (Priority 25, after memory files at 20)
add_filter(
'datamachine_directives',
function ( $directives ) {
$directives[] = array(
'class' => ChatContextDirective::class,
'priority' => 25,
'contexts' => array( 'chat' ),
);
return $directives;
}
);
82 changes: 0 additions & 82 deletions inc/Api/System/SystemAgentDirective.php

This file was deleted.

80 changes: 80 additions & 0 deletions inc/Api/System/SystemContextDirective.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php
/**
* System Context Directive
*
* Operational context for system tasks. Identity comes from memory files (SOUL.md, etc.).
*
* @package DataMachine\Api\System
* @since 0.13.7
*/

namespace DataMachine\Api\System;

if ( ! defined( 'ABSPATH' ) ) {
exit;
}

/**
* System Context Directive
*
* Provides system task operational context — task behavior rules and
* capability hints. Agent identity comes from memory files.
*/
class SystemContextDirective implements \DataMachine\Engine\AI\Directives\DirectiveInterface {

public static function get_outputs( string $provider_name, array $tools, ?string $step_id = null, array $payload = array() ): array {
$directive = self::get_directive( $tools );

return array(
array(
'type' => 'system_text',
'content' => $directive,
),
);
}

/**
* Generate system context directive.
*
* @param array $tools Available tools.
* @return string Directive text.
*/
private static function get_directive( $tools ): string {
$directive = '# System Task Context' . "\n\n"
. 'This is a background system task — not a chat session. Your identity and knowledge are already loaded from your memory files above. Use that context.' . "\n\n"
. '## Task Behavior' . "\n\n"
. '- Execute the task described in the user message below.' . "\n"
. '- Return exactly what the task asks for — no extra commentary, no meta-discussion.' . "\n"
. '- Apply your knowledge of this site, its voice, and its conventions from your memory files.' . "\n\n"
. '## Session Title Generation' . "\n\n"
. 'When asked to generate a chat session title: create a concise, descriptive title (3-6 words) capturing the discussion essence. Return ONLY the title text, under 100 characters.' . "\n\n"
. '## GitHub Issue Creation' . "\n\n"
. 'When using create_github_issue: include a clear title and detailed body with context, reproduction steps, and relevant log snippets. Use labels to categorize. Route to the most appropriate repo. Never create duplicates.';

// List available repos dynamically.
if ( class_exists( '\DataMachine\Abilities\Fetch\GitHubAbilities' ) ) {
$repos = \DataMachine\Abilities\Fetch\GitHubAbilities::getRegisteredRepos();
if ( ! empty( $repos ) ) {
$directive .= "\n\n" . 'Available repositories for issue creation:' . "\n";
foreach ( $repos as $entry ) {
$directive .= '- ' . $entry['owner'] . '/' . $entry['repo'] . ' — ' . $entry['label'] . "\n";
}
}
}

return $directive;
}
}

// Register with directive system (Priority 25, after memory files at 20)
add_filter(
'datamachine_directives',
function ( $directives ) {
$directives[] = array(
'class' => SystemContextDirective::class,
'priority' => 25,
'contexts' => array( 'system' ),
);
return $directives;
}
);
Loading
Loading