Skip to content

Commit 0bf6cc3

Browse files
authored
Update ProcessOptions builder to handle new fields (#753)
This commit introduces builder options for ProcessOptions fields introduced since the builder's introduction. See #659 Signed-off-by: Arjen Poutsma <poutsma@mac.com>
1 parent 72c9c24 commit 0bf6cc3

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed

embabel-agent-api/src/main/kotlin/com/embabel/agent/core/ProcessOptions.kt

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ data class ProcessOptions(
285285
*/
286286
class Builder internal constructor() {
287287

288-
private var processOptions = ProcessOptions.DEFAULT
288+
private var processOptions = DEFAULT
289289

290290
/**
291291
* Set the context identifier to use for the invocation. Can be null.
@@ -300,6 +300,16 @@ data class ProcessOptions(
300300
return this
301301
}
302302

303+
/**
304+
* Sets the identities associated with the process.
305+
* @param identities the identities
306+
* @return this [Builder]
307+
*/
308+
fun identities(identities: Identities): Builder {
309+
this.processOptions = processOptions.copy(identities = identities)
310+
return this
311+
}
312+
303313
/**
304314
* An existing blackboard to use for this invocation.
305315
* By default, it will be modified as the process runs.
@@ -387,6 +397,40 @@ data class ProcessOptions(
387397
return this
388398
}
389399

400+
/**
401+
* Whether to prune the agent to only relevant actions
402+
* @param prune true to prune the agent to only relevant actions
403+
* @return this [Builder]
404+
*/
405+
fun prune(prune: Boolean): Builder {
406+
this.processOptions = processOptions.copy(prune = prune)
407+
return this
408+
}
409+
410+
/**
411+
* Add a listener to the list of [AgenticEventListener]s.
412+
* @param listener the listener to add
413+
* @return this [Builder]
414+
*/
415+
fun listener(listener: AgenticEventListener): Builder {
416+
val listeners = this.processOptions.listeners + listener
417+
this.processOptions = processOptions.copy(listeners = listeners)
418+
return this
419+
}
420+
421+
/**
422+
* Manipulate the listeners with the given consumer.
423+
* The list provided to the consumer can be used to remove listeners, change ordering, etc.
424+
* @param listener the listener to add
425+
* @return this [Builder]
426+
*/
427+
fun listeners(consumer: Consumer<List<AgenticEventListener>>): Builder {
428+
val listeners = this.processOptions.listeners.toMutableList()
429+
consumer.accept(listeners)
430+
this.processOptions = processOptions.copy(listeners = listeners)
431+
return this
432+
}
433+
390434
/**
391435
* Build the [ProcessOptions].
392436
* @return a newly built [ProcessOptions]

embabel-agent-api/src/test/java/com/embabel/agent/core/ProcessOptionsBuilderTest.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,29 @@
1616
package com.embabel.agent.core;
1717

1818
import com.embabel.agent.core.support.InMemoryBlackboard;
19-
import com.embabel.agent.testing.unit.FakeOperationContext;
19+
import com.embabel.agent.event.AgenticEventListener;
2020
import org.junit.jupiter.api.Test;
2121

22+
import java.util.List;
23+
2224
import static org.junit.jupiter.api.Assertions.assertEquals;
2325
import static org.junit.jupiter.api.Assertions.assertTrue;
2426

2527
class ProcessOptionsBuilderTest {
2628

2729
@Test
2830
void builder() {
31+
var identities = new Identities();
2932
var blackboard = new InMemoryBlackboard();
33+
var listener = AgenticEventListener.Companion.getDevNull();
3034

3135
var po = ProcessOptions.builder()
36+
.identities(identities)
3237
.blackboard(blackboard)
3338
.test(true)
39+
.prune(true)
40+
.listener(listener)
41+
.listeners(listeners -> assertEquals(List.of(listener), listeners))
3442
.verbosity(vb -> vb
3543
.showPrompts(true)
3644
.showLlmResponses(true)
@@ -45,8 +53,11 @@ void builder() {
4553
)
4654
.build();
4755

56+
assertEquals(identities, po.getIdentities());
4857
assertEquals(blackboard, po.getBlackboard());
4958
assertTrue(po.getTest());
59+
assertTrue(po.getPrune());
60+
assertEquals(List.of(listener), po.getListeners());
5061

5162
assertTrue(po.getVerbosity().getShowPrompts());
5263
assertTrue(po.getVerbosity().getShowLlmResponses());

0 commit comments

Comments
 (0)