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
40 changes: 23 additions & 17 deletions packages/junior-evals/src/behavior-harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1488,7 +1488,7 @@ function buildRuntimeServices(
: {}),
replyExecutor: {
agentRunner: {
run: async (text, context) => {
run: async (request) => {
replyCallCount += 1;
const mockImageGeneration = scenario.overrides?.mock_image_generation;
if (scenario.overrides?.fail_reply_call === replyCallCount) {
Expand All @@ -1497,7 +1497,7 @@ function buildRuntimeServices(
const replyResult = replyResults[replyCallCount - 1];
if (replyResult) {
if (replyResult.stream_text) {
await context?.onTextDelta?.(replyResult.stream_text);
await request.observers?.onTextDelta?.(replyResult.stream_text);
}
replyState.successfulCount += 1;
observations.toolInvocations.push(
Expand Down Expand Up @@ -1557,7 +1557,7 @@ function buildRuntimeServices(
"VERCEL_OIDC_TOKEN",
]);
const baseToolOverrides: ToolHooks["toolOverrides"] = {
...(context?.toolOverrides ?? {}),
...(request.policy?.toolOverrides ?? {}),
};
const toolOverrides = {
...baseToolOverrides,
Expand All @@ -1572,21 +1572,27 @@ function buildRuntimeServices(
delete process.env.VERCEL_OIDC_TOKEN;
}
try {
const outcome = await generateAssistantReply(text, {
...context,
turnDeadlineAtMs: Math.min(
context?.turnDeadlineAtMs ?? Number.POSITIVE_INFINITY,
Date.now() + replyTimeoutMs,
),
onToolInvocation: (invocation) => {
observations.toolInvocations.push(
toEvalToolInvocation(invocation),
);
const outcome = await generateAssistantReply({
...request,
policy: {
...request.policy,
turnDeadlineAtMs: Math.min(
request.policy?.turnDeadlineAtMs ?? Number.POSITIVE_INFINITY,
Date.now() + replyTimeoutMs,
),
...(env.configuredSkillDirs.length > 0
? { skillDirs: env.configuredSkillDirs }
: {}),
toolOverrides,
},
observers: {
...request.observers,
onToolInvocation: (invocation) => {
observations.toolInvocations.push(
toEvalToolInvocation(invocation),
);
},
},
...(env.configuredSkillDirs.length > 0
? { skillDirs: env.configuredSkillDirs }
: {}),
toolOverrides,
});
replyState.successfulCount += 1;
return outcome;
Expand Down
109 changes: 60 additions & 49 deletions packages/junior/src/chat/agent-dispatch/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,60 +289,71 @@ export async function runAgentDispatchSlice(
excludeMessageId: userMessageId,
});

const outcome = await deps.agentRunner.run(dispatch.input, {
authorizationFlowMode: "disabled",
credentialContext: {
actor: dispatch.actor,
...(dispatch.credentialSubject
? { subject: dispatch.credentialSubject }
: {}),
const outcome = await deps.agentRunner.run({
input: {
messageText: dispatch.input,
conversationContext,
piMessages: conversation.piMessages,
},
configuration,
channelConfiguration,
conversationContext,
artifactState: artifacts,
piMessages: conversation.piMessages,
destination: dispatch.destination,
source: dispatch.source,
dispatch: {
actor: dispatch.actor,
metadata: dispatch.metadata,
plugin: dispatch.plugin,
},
correlation: {
conversationId,
threadId: conversationId,
turnId,
runId: dispatch.id,
channelId: dispatch.destination.channelId,
teamId: dispatch.destination.teamId,
},
surface: "api",
toolChannelId: dispatch.destination.channelId,
sandbox: {
sandboxId,
sandboxDependencyProfileHash,
},
onSandboxAcquired: async (sandbox) => {
sandboxId = sandbox.sandboxId;
sandboxDependencyProfileHash = sandbox.sandboxDependencyProfileHash;
await persistRuntimePatch({
routing: {
credentialContext: {
actor: dispatch.actor,
...(dispatch.credentialSubject
? { subject: dispatch.credentialSubject }
: {}),
},
destination: dispatch.destination,
source: dispatch.source,
dispatch: {
actor: dispatch.actor,
metadata: dispatch.metadata,
plugin: dispatch.plugin,
},
correlation: {
conversationId,
threadId: conversationId,
conversation,
artifacts,
sandboxId,
sandboxDependencyProfileHash,
});
turnId,
runId: dispatch.id,
channelId: dispatch.destination.channelId,
teamId: dispatch.destination.teamId,
},
surface: "api",
toolChannelId: dispatch.destination.channelId,
},
onArtifactStateUpdated: async (nextArtifacts) => {
artifacts = nextArtifacts;
await persistRuntimePatch({
threadId: conversationId,
conversation,
artifacts,
policy: {
authorizationFlowMode: "disabled",
configuration,
channelConfiguration,
sandbox: {
sandboxId,
sandboxDependencyProfileHash,
});
},
},
state: {
artifactState: artifacts,
},
durability: {
onSandboxAcquired: async (sandbox) => {
sandboxId = sandbox.sandboxId;
sandboxDependencyProfileHash = sandbox.sandboxDependencyProfileHash;
await persistRuntimePatch({
threadId: conversationId,
conversation,
artifacts,
sandboxId,
sandboxDependencyProfileHash,
});
},
onArtifactStateUpdated: async (nextArtifacts) => {
artifacts = nextArtifacts;
await persistRuntimePatch({
threadId: conversationId,
conversation,
artifacts,
sandboxId,
sandboxDependencyProfileHash,
});
},
},
});
if (outcome.status === "awaiting_auth") {
Expand Down
111 changes: 62 additions & 49 deletions packages/junior/src/chat/local/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,62 +223,75 @@ export async function runLocalAgentTurn(
fallback: conversation.piMessages,
});
piMessagesBeforeRun = piMessages;
const outcome = await deps.agentRunner.run(text, {
authorizationFlowMode: "disabled",
conversationContext: buildConversationContext(conversation, {
excludeMessageId: userMessageId,
}),
artifactState: artifacts,
credentialContext: {
actor: { type: "system", id: "local-cli" },
const outcome = await deps.agentRunner.run({
input: {
messageText: text,
conversationContext: buildConversationContext(conversation, {
excludeMessageId: userMessageId,
}),
piMessages,
},
destination,
source,
requester: {
fullName: "Local CLI",
platform: "local",
userId: "local-cli",
userName: "local",
},
piMessages,
surface: "internal",
correlation: {
conversationId: input.conversationId,
turnId,
runId: turnId,
},
sandbox: {
sandboxId,
sandboxDependencyProfileHash,
},
onArtifactStateUpdated: async (nextArtifacts) => {
artifacts = nextArtifacts;
await persistThreadStateById(input.conversationId, {
artifacts,
conversation,
sandboxId,
sandboxDependencyProfileHash,
});
routing: {
credentialContext: {
actor: { type: "system", id: "local-cli" },
},
destination,
source,
requester: {
fullName: "Local CLI",
platform: "local",
userId: "local-cli",
userName: "local",
},
surface: "internal",
correlation: {
conversationId: input.conversationId,
turnId,
runId: turnId,
},
},
onSandboxAcquired: async (sandbox) => {
sandboxId = sandbox.sandboxId;
sandboxDependencyProfileHash = sandbox.sandboxDependencyProfileHash;
await persistThreadStateById(input.conversationId, {
artifacts,
conversation,
policy: {
authorizationFlowMode: "disabled",
sandbox: {
sandboxId,
sandboxDependencyProfileHash,
});
},
},
onStatus: async (status) => {
await deps.onStatus?.(status.text);
state: {
artifactState: artifacts,
},
onTextDelta: deps.onTextDelta,
onToolInvocation: async (invocation) => {
await deps.onToolInvocation?.(invocation);
observers: {
onStatus: async (status) => {
await deps.onStatus?.(status.text);
},
onTextDelta: deps.onTextDelta,
onToolInvocation: async (invocation) => {
await deps.onToolInvocation?.(invocation);
},
onToolResult: async (result) => {
await deps.onToolResult?.(result);
},
},
onToolResult: async (result) => {
await deps.onToolResult?.(result);
durability: {
onArtifactStateUpdated: async (nextArtifacts) => {
artifacts = nextArtifacts;
await persistThreadStateById(input.conversationId, {
artifacts,
conversation,
sandboxId,
sandboxDependencyProfileHash,
});
},
onSandboxAcquired: async (sandbox) => {
sandboxId = sandbox.sandboxId;
sandboxDependencyProfileHash = sandbox.sandboxDependencyProfileHash;
await persistThreadStateById(input.conversationId, {
artifacts,
conversation,
sandboxId,
sandboxDependencyProfileHash,
});
},
},
});
if (outcome.status !== "completed") {
Expand Down
Loading
Loading