Skip to content

Commit

Permalink
refactor planner properties
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcheng1982 committed May 9, 2024
1 parent 0e093a7 commit 8424b41
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.github.llmagentbuilder.core.chatmemory.ChatMemoryStore;
import io.github.llmagentbuilder.core.chatmemory.InMemoryChatMemoryStore;
import io.github.llmagentbuilder.core.planner.reactjson.ReActJsonPlannerFactory;
import io.github.llmagentbuilder.core.planner.simple.SimplePlannerFactory;
import io.github.llmagentbuilder.core.tool.AgentToolFunctionCallbackContext;
import io.github.llmagentbuilder.core.tool.AgentToolsProvider;
import io.github.llmagentbuilder.core.tool.AgentToolsProviderFactory;
Expand Down Expand Up @@ -66,8 +67,11 @@ public ChatMemoryStore chatMemoryStore() {
}

@Bean
@Primary
@ConditionalOnProperty(prefix = ChatAgentProperties.CONFIG_PREFIX
+ ".planner.reActJson", name = "enabled", matchIfMissing = true)
@ConditionalOnMissingBean
public Planner planner(ChatClient chatClient,
public Planner reActJsonPlanner(ChatClient chatClient,
ChatOptions chatOptions,
Optional<ChatMemoryStore> chatMemoryStore,
AgentToolsProvider agentToolsProvider,
Expand All @@ -77,7 +81,30 @@ public Planner planner(ChatClient chatClient,
chatClient,
chatOptions,
agentToolsProvider,
properties.getReActJson().getSystemInstructions(),
properties.getPlanner().getSystemInstructions(),
chatMemoryStore.orElse(null),
properties.tracingEnabled() ? observationRegistry.orElse(null)
: null,
properties.metricsEnabled() ? meterRegistry.orElse(null)
: null
);
}

@Bean
@ConditionalOnProperty(prefix = ChatAgentProperties.CONFIG_PREFIX
+ ".planner.simple", name = "enabled")
@ConditionalOnMissingBean
public Planner simplePlanner(ChatClient chatClient,
ChatOptions chatOptions,
Optional<ChatMemoryStore> chatMemoryStore,
AgentToolsProvider agentToolsProvider,
Optional<ObservationRegistry> observationRegistry,
Optional<MeterRegistry> meterRegistry) {
return SimplePlannerFactory.INSTANCE.create(
chatClient,
chatOptions,
agentToolsProvider,
properties.getPlanner().getSystemInstructions(),
chatMemoryStore.orElse(null),
properties.tracingEnabled() ? observationRegistry.orElse(null)
: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class ChatAgentProperties {
private String usageInstruction = "Ask me anything";

@NestedConfigurationProperty
private ReActJson reActJson = new ReActJson();
private Planner planner = new Planner();

@NestedConfigurationProperty
private Memory memory = new Memory();
Expand Down Expand Up @@ -74,12 +74,13 @@ public void setUsageInstruction(String usageInstruction) {
this.usageInstruction = usageInstruction;
}

public ReActJson getReActJson() {
return reActJson;
public Planner getPlanner() {
return planner;
}

public void setReActJson(ReActJson reActJson) {
this.reActJson = reActJson;
public void setPlanner(
Planner planner) {
this.planner = planner;
}

public Memory getMemory() {
Expand Down Expand Up @@ -126,17 +127,67 @@ public boolean metricsEnabled() {
return metrics == null || metrics.isEnabled();
}

public static class ReActJson {
public static class Planner {

private String systemInstructions;

@NestedConfigurationProperty
private ReActJson reActJson = new ReActJson();

@NestedConfigurationProperty
private Simple simple = new Simple();

public String getSystemInstructions() {
return systemInstructions;
}

public void setSystemInstructions(String systemInstructions) {
this.systemInstructions = systemInstructions;
}

public ReActJson getReActJson() {
return reActJson;
}

public void setReActJson(ReActJson reActJson) {
this.reActJson = reActJson;
}

public Simple getSimple() {
return simple;
}

public void setSimple(
Simple simple) {
this.simple = simple;
}
}

public static class ReActJson {

private boolean enabled = true;

public boolean isEnabled() {
return enabled;
}

public void setEnabled(boolean enabled) {
this.enabled = enabled;
}

}

public static class Simple {

private boolean enabled = false;

public boolean isEnabled() {
return enabled;
}

public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
}

public static class Memory {
Expand Down

0 comments on commit 8424b41

Please sign in to comment.