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
6 changes: 6 additions & 0 deletions spring-ai-alibaba-graph-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,12 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-openai</artifactId>
<scope>provided</scope>
</dependency>

</dependencies>

<reporting>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/*
* Copyright 2024-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.agentscope.core;

import io.agentscope.core.memory.Memory;
import io.agentscope.core.message.Msg;
import io.agentscope.core.model.Model;
import io.agentscope.core.tool.Toolkit;
import reactor.core.publisher.Flux;

import java.util.List;

public class ReActAgent {

private final String name;

private final String sysPrompt;

private final Model model;

private final Toolkit toolkit;

private final Memory memory;

private final boolean parallelToolCalls;

private final int maxIters;

public ReActAgent(String name, String sysPrompt, Model model, Toolkit toolkit, Memory memory,
boolean parallelToolCalls, int maxIters) {
this.name = name;
this.sysPrompt = sysPrompt;
this.model = model;
this.toolkit = toolkit;
this.memory = memory;
this.parallelToolCalls = parallelToolCalls;
this.maxIters = maxIters;
}

public Flux<Msg> stream(Msg msg) {
return Flux.empty();
}

public Msg call(Msg msg) {
return null;
}

public Flux<Msg> stream(List<Msg> msg) {
return Flux.empty();
}

public Msg call(List<Msg> msg) {
return null;
}

public static Builder builder() {
return new Builder();
}

public static class Builder {

private String name;

private String sysPrompt;

private Model model;

private Toolkit toolkit;

private Memory memory;

private boolean parallelToolCalls;

private int maxIters;

private Builder() {
}

public Builder name(String name) {
this.name = name;
return this;
}

public Builder sysPrompt(String sysPrompt) {
this.sysPrompt = sysPrompt;
return this;
}

public Builder model(Model model) {
this.model = model;
return this;
}

public Builder toolkit(Toolkit toolkit) {
this.toolkit = toolkit;
return this;
}

public Builder memory(Memory memory) {
this.memory = memory;
return this;
}

public Builder parallelToolCalls(boolean parallelToolCalls) {
this.parallelToolCalls = parallelToolCalls;
return this;
}

public Builder maxIters(int maxIters) {
this.maxIters = maxIters;
return this;
}

public ReActAgent build() {
return new ReActAgent(name, sysPrompt, model, toolkit, memory, parallelToolCalls, maxIters);
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2024-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.agentscope.core.memory;

import org.springframework.ai.chat.messages.Message;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

public class InMemoryMemory implements Memory {

private final List<Message> messages = new CopyOnWriteArrayList<>();

@Override
public void addMessage(Message message) {
messages.add(message);
}

@Override
public List<Message> getMessages() {
return List.copyOf(messages);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2024-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.agentscope.core.memory;

import org.springframework.ai.chat.messages.Message;

import java.util.List;

public interface Memory {

void addMessage(Message message);

List<Message> getMessages();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright 2024-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.agentscope.core.message;

public class ContentBlock {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright 2024-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.agentscope.core.message;

public class Msg {

private final String name;

private final MsgRole role;

private final ContentBlock content;

private Msg(String name, MsgRole role, ContentBlock content) {
this.name = name;
this.role = role;
this.content = content;
}

public static Builder builder() {
return new Builder();
}

public static class Builder {

private String name;

private MsgRole role;

private ContentBlock content;

public Builder name(String name) {
this.name = name;
return this;
}

public Builder role(MsgRole role) {
this.role = role;
return this;
}

public Builder content(ContentBlock content) {
this.content = content;
return this;
}

public Msg build() {
return new Msg(name, role, content);
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright 2024-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.agentscope.core.message;

public enum MsgRole {

USER, ASSISTANT, SYSTEM

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2024-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.agentscope.core.message;

public class TextBlock extends ContentBlock {

private final String text;

private TextBlock(String text) {
this.text = text;
}

public static Builder builder() {
return new Builder();
}

public static class Builder {

private String text;

public Builder text(String text) {
this.text = text;
return this;
}

public TextBlock build() {
return new TextBlock(text);
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright 2024-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.agentscope.core.model;

import org.springframework.ai.chat.model.ChatModel;

public interface Model {

ChatModel chatModel();

}
Loading
Loading