Jose
11/04/2025, 9:59 AMval nodeFindId by node<List<Document>, List<Document>>("find_id") { b ->
val list = b.withIndex().parMap(concurrency = 10) { b ->
logger.info("Extracting ID from document ${b.index + 1}/${b.size} - ${b.value.identifier}")
withContext(IO) {
llm.writeSession {
rewritePrompt {
prompt("id_search_prompt") {
system(
"""You are provided a legal text from which you have to extract the ID identifier.
A ID identifier is a numeric code that identifies a specific grant call in the ID system.
If there is no ID identifier in the text, respond with 'NOT_FOUND'.
Respond only with the ID identifier or 'NOT_FOUND', do not add any additional text
"""
)
user("Legal text: \n\n${b.value.pages.joinToString("\n\n")}")
}
}
val id = requestLLM().content
b.value.copy(id = id)
}
}
}
list.filter { it.id != null && it.id != "NOT_FOUND" }
}
2025-11-04T10:28:37.784+01:00 INFO 67031 --- [-agent] [-2 @coroutine#2] agent.AgentFactory : Extracting ID from document 0/97 - 2025-40119
2025-11-04T10:28:37.799+01:00 INFO 67031 --- [-agent] [-2 @coroutine#3] agent.AgentFactory : Extracting ID from document 1/97 - 2025-40120
2025-11-04T10:28:37.799+01:00 INFO 67031 --- [-agent] [-2 @coroutine#4] agent.AgentFactory : Extracting ID from document 2/97 - 2025-40121
2025-11-04T10:28:37.799+01:00 INFO 67031 --- [-agent] [-2 @coroutine#5] agent.AgentFactory : Extracting ID from document 3/97 - 2025-40122
2025-11-04T10:28:37.799+01:00 INFO 67031 --- [-agent] [-2 @coroutine#6] agent.AgentFactory : Extracting ID from document 4/97 - 2025-40123
2025-11-04T10:28:37.799+01:00 INFO 67031 --- [-agent] [-2 @coroutine#7] agent.AgentFactory : Extracting ID from document 5/97 - 2025-40124
2025-11-04T10:28:37.799+01:00 INFO 67031 --- [-agent] [-2 @coroutine#8] agent.AgentFactory : Extracting ID from document 6/97 - 2025-40125
2025-11-04T10:28:37.799+01:00 INFO 67031 --- [-agent] [-2 @coroutine#9] agent.AgentFactory : Extracting ID from document 7/97 - 2025-40126
2025-11-04T10:28:37.800+01:00 INFO 67031 --- [-agent] [2 @coroutine#10] agent.AgentFactory : Extracting ID from document 8/97 - 2025-40127
2025-11-04T10:28:37.800+01:00 INFO 67031 --- [-agent] [2 @coroutine#11] agent.AgentFactory : Extracting ID from document 9/97 - 2025-40128
2025-11-04T10:28:38.964+01:00 INFO 67031 --- [-agent] [2 @coroutine#12] agent.AgentFactory : Extracting ID from document 10/97 - 2025-40129
2025-11-04T10:28:40.041+01:00 INFO 67031 --- [-agent] [1 @coroutine#13] agent.AgentFactory : Extracting ID from document 11/97 - 2025-40130
2025-11-04T10:28:41.862+01:00 INFO 67031 --- [-agent] [1 @coroutine#14] agent.AgentFactory : Extracting ID from document 12/97 - 2025-40131Vadim Briliantov
11/04/2025, 3:00 PMJose
11/04/2025, 4:02 PMval nodeName by parallel<Input, Output>(
firstNode, secondNode, thirdNode /* Add more nodes if needed */
)
In my case I have a list of an undetermined number of elements and for each of them I have to make a parallel request.
🤔Andrey Bragin
11/04/2025, 4:27 PMVadim Briliantov
11/04/2025, 4:31 PMval nodes = (0 until Random.nextInt(100, 200)).map { i ->
val ithNode by node<String, String>(name = "n_$i") { input -> "$input $i" }
ithNode
}
val parallelComputation by parallel<String, String>(*nodes.toTypedArray()) {
selectByMax { it.length } // or some other selection strategy
}Vadim Briliantov
11/04/2025, 4:32 PM* is what does the trick in Kotlin to pass an array instead of vararg argumentJose
11/05/2025, 8:26 AM