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
11 changes: 7 additions & 4 deletions inc/Core/JobArtifacts.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,13 @@ private function agent_memory_artifacts( array $job, array $agent, array $tool_c
continue;
}

$agent_id = (int) ( $tool_call['agent_id'] ?? $default_agent_id );
$user_id = (int) ( $tool_call['user_id'] ?? ( $job['user_id'] ?? 0 ) );
$layer = AgentMemoryFile::resolve_layer_for( $filename );
$key = $layer . ':' . $agent_id . ':' . $user_id . ':' . $filename;
$agent_id = (int) ( $tool_call['agent_id'] ?? 0 );
if ( $agent_id <= 0 && $default_agent_id > 0 ) {
$agent_id = $default_agent_id;
}
$user_id = (int) ( $tool_call['user_id'] ?? ( $job['user_id'] ?? 0 ) );
$layer = AgentMemoryFile::resolve_layer_for( $filename );
$key = $layer . ':' . $agent_id . ':' . $user_id . ':' . $filename;

$files[ $key ] = array(
'agent_id' => $agent_id,
Expand Down
3 changes: 3 additions & 0 deletions inc/Engine/AI/Tools/Global/AgentMemory.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ private function handleGet( array $parameters ): array {
return array(
'success' => true,
'data' => $result,
'scope' => $scope,
'tool_name' => 'agent_memory',
);
}
Expand Down Expand Up @@ -157,6 +158,7 @@ private function handleUpdate( array $parameters ): array {
return array(
'success' => true,
'data' => $result,
'scope' => $scope,
'tool_name' => 'agent_memory',
);
}
Expand Down Expand Up @@ -202,6 +204,7 @@ private function handleListSections( array $parameters = array() ): array {
return array(
'success' => true,
'data' => $result,
'scope' => $scope,
'tool_name' => 'agent_memory',
);
}
Expand Down
5 changes: 3 additions & 2 deletions inc/Engine/AI/conversation-loop.php
Original file line number Diff line number Diff line change
Expand Up @@ -1086,8 +1086,9 @@ function datamachine_summarize_tool_execution_results( array $tool_execution_res
}

if ( 'agent_memory' === $tool_name ) {
$summary['user_id'] = isset( $parameters['user_id'] ) ? (int) $parameters['user_id'] : null;
$summary['agent_id'] = isset( $parameters['agent_id'] ) ? (int) $parameters['agent_id'] : null;
$scope = is_array( $tool_result['scope'] ?? null ) ? $tool_result['scope'] : array();
$summary['user_id'] = isset( $scope['user_id'] ) ? (int) $scope['user_id'] : ( isset( $parameters['user_id'] ) ? (int) $parameters['user_id'] : null );
$summary['agent_id'] = isset( $scope['agent_id'] ) ? (int) $scope['agent_id'] : ( isset( $parameters['agent_id'] ) ? (int) $parameters['agent_id'] : null );
$summary['action'] = isset( $parameters['action'] ) ? sanitize_key( (string) $parameters['action'] ) : null;
$summary['file'] = isset( $parameters['file'] ) ? sanitize_file_name( (string) $parameters['file'] ) : 'MEMORY.md';
$summary['section'] = isset( $parameters['section'] ) ? sanitize_text_field( (string) $parameters['section'] ) : null;
Expand Down
6 changes: 4 additions & 2 deletions tests/job-artifacts-daily-memory-smoke.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,11 @@

$assert(
false !== strpos( $loop, "'agent_memory' === \$tool_name" )
&& false !== strpos( $loop, "\$tool_result['scope']" )
&& false !== strpos( $loop, "\$summary['file']" )
&& false !== strpos( $loop, "\$summary['section']" )
&& false !== strpos( $loop, "'update' === \$summary['action']" ),
'agent memory update summaries preserve file, section, action, and content for artifact export'
'agent memory update summaries preserve resolved scope, file, section, action, and content for artifact export'
);

$assert(
Expand All @@ -110,8 +111,9 @@
$assert(
false !== strpos( $job_artifacts, 'new AgentMemoryFile' )
&& false !== strpos( $job_artifacts, 'get_all()' )
&& false !== strpos( $job_artifacts, '$agent_id <= 0 && $default_agent_id > 0' )
&& false !== strpos( $job_artifacts, 'agent_memory_fallback_content' ),
'agent memory artifacts export the full updated file content with a write-content fallback'
'agent memory artifacts export the full updated file content using the resolved job agent when needed'
);

$assert(
Expand Down
Loading