Skip to content

Question: Introduce type safety to outputKey handling #1955

@DepickereSven

Description

@DepickereSven

Hello

I have some questions about the understanding and implementation of the #1903.
I'm using the workflow pattern as the following instead of declarative API:

    public void test() {
        StoryCreatorWorkflow storyCreatorWorkflow = AgenticServices
                .sequenceBuilder(StoryCreatorWorkflow.class)
                .subAgents(createCreativeWriteAgent(), createAudienceEditorAgent(), createStyleEditorAgent())
                .outputKey("story-final")
                .build();

        storyCreatorWorkflow.write("topic", "style", "audience");

    }

    public CreativeWriter createCreativeWriteAgent() {
        return AgenticServices.agentBuilder(CreativeWriter.class).outputKey("story-initial").build();
    }

    public AudienceEditor createAudienceEditorAgent() {
        return AgenticServices.agentBuilder(AudienceEditor.class).outputKey("story-edited").build();
    }

    public StyleEditor createStyleEditorAgent() {
        return AgenticServices.agentBuilder(StyleEditor.class).outputKey("story-final").build();
    }

    public interface StoryCreatorWorkflow {

        @Agent
        String write(@V("topic") String topic, @V("style") String style, @V("audience") String audience);

    }

public interface CreativeWriter {

        @UserMessage("""
                You are a creative writer.
                Generate a draft of a story long no more than 3 sentence around the given topic.
                Return only the story and nothing else.
                The topic is {{topic}}.
                """)
        @Agent("Generate a story based on the given topic")
        String generateStory(@V("topic") String topic);
    }

    public interface AudienceEditor {

        @UserMessage("""
                You are a professional editor.
                Analyze and rewrite the following story to better align with the target audience of {{audience}}.
                Return only the story and nothing else.
                The story is "{{story}}".
                """)
        @Agent("Edit a story to better fit a given audience")
        String editStory(@V("story") String story, @V("audience") String audience);
    }

    public interface StyleEditor {

        @UserMessage("""
                You are a professional editor.
                Analyze and rewrite the following story to better fit and be more coherent with the {{style}} style.
                Return only the story and nothing else.
                The story is "{{story}}".
                """)
        @Agent("Edit a story to better fit a given style")
        String editStory(@V("story") String story, @V("style") String style);
    }

After running that code, I would expect that the error would be No agent provides an output key named 'story'.
But the error is rather No agent provides an output key named 'topic'.

The original test cases written for this also throws that error:

As long as you don't do the following changes to the test code

    @Inject
    StoryCreator storyCreator;

    @Test
    public void test() {
        storyCreator.write("topic", "style", "audience");
	}

To me, this doesn't seem like expected behavior if you're not using the declarative API.
But it makes me wonder is this expected behavior if you're using the declarative API, and you're not injecting the storyCreator that error also says No agent provides an output key named 'topic'

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions